Nginx配置max_fails fail_timeout 不起作用 - stub_status - 调试 nginx --with-debug

0.stub_status

configure arguments: --prefix=/usr/local/tengine --with-http_realip_module --with-http_gzip_static_module --with-pcre --with-http_stub_status_module --with-http_ssl_module --add-module=/opt/nginx-goodies-nginx-sticky-module-ng

复制代码
[root@slave1 conf.d]# cat myserver.conf
  server {
  
    listen 80;
    client_max_body_size 4G;

   
    server_name example.com 129.211.117.78 www.example.com;

    keepalive_timeout 5;

    access_log  /var/log/nginx/access.log ;
    error_log  /var/log/nginx/errors.log warn;
    location / {
      proxy_pass http://app_server1;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_set_header Host $http_host;

      proxy_redirect off;

    }

location /media  {
    alias /opt/sudjango/nginxdjango/media;
  }
 
  location /static {
    alias /opt/sudjango/nginxdjango/static;
  }
  location /ngx_status
  {
   stub_status on;
#   access_log off;
   allow all;
  }
    error_page 500 502 503 504 /500.html;
    location = /500.html {
      root /path/to/app/current/public;
    }
  }
[root@slave1 conf.d]# 
复制代码

 

1.默认配置时,http_404状态不被认为是失败的尝试。

2.location

复制代码
location / {
            proxy_pass http://tomcatserver1;
            index  index.html index.htm;
            # proxy_next_upstream
            proxy_next_upstream error timeout invalid_header http_500 http_503 http_404; 
       ##如果后端的服务器返回502、504、执行超时等错误,自动将请求转发到upstream负载均衡池中的另一台服务器,实现故障转移。
     #https://forezp.blog.csdn.net/article/details/78616591
proxy_connect_timeout 7s; proxy_read_timeout 7s; proxy_send_timeout 7s; }
复制代码

3.配置nginx.conf文件 具体配置如下

 upstream report{                                                                                                                       
         server localhost1:18080 max_fails=10 fail_timeout=7s;                                                                                                            
         server localhost1:28080 max_fails=10 fail_timeout=7s;                                                                                                            
        server localhost2:18080 max_fails=10 fail_timeout=7s;                                                                                                             
        server localhost2:28080 max_fails=10 fail_timeout=7s;                                                                                                             
        #ip_hash;                                                                                                                              
    } 

 

4.参考:https://blog.csdn.net/u011202188/article/details/88802035

5./home/wwlocal/wwlnginx/conf/nginx.conf

复制代码
worker_processes 8;
# worker_cpu_affinity 0001 0010 0100 1000;
error_log  log/error.log info;
# error_log  log/error.log debug;
# error_log  log/error.log  notice;
# error_log  log/error.log  info;
pid        sbin/nginx.pid;
worker_rlimit_nofile 102400;
events {
    worker_connections  102400;
}
http {
    include mime.types;
    default_type text/plain;
    log_format main '$remote_addr $host [$time_local] $status $request_time $body_bytes_sent $request_uri $upstream_addr $upstream_status " $http_user_agent" $upstream_response_time $http_headhex $connection';
    access_log logs/access.log main;
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    server_tokens off;
    keepalive_timeout 60;
    keepalive_requests 2048;
    gzip on;
    gzip_static on;
    gzip_min_length 1000;
    gzip_buffers 4 8k;
    gzip_comp_level 7;
    gzip_http_version 1.1;
    gzip_vary on;
    gzip_types text/plain application/x-javascript text/css application/xml image/jpeg image/gif image/png;
    proxy_max_temp_file_size 0;
    proxy_buffer_size 64k;
    proxy_buffers 4 64k;
    proxy_connect_timeout 1s;
    client_header_buffer_size 16k;
    large_client_header_buffers 4 32k;
    client_max_body_size 80m;
    client_body_buffer_size 60m;
    server_names_hash_max_size 1024;
    server_names_hash_bucket_size 1024;
    underscores_in_headers on;  
    #upstream wwlproxy{
    #    server 255.255.255.255:80 max_fails=10 fail_timeout=1s;
    #    server 255.255.255.255:80 max_fails=0 backup;
    #}短链后端配置请到/home/wwlocal/wwlnginx/conf/webhost.conf
    include webhost.conf;
    server {
        listen 80;
        location / {
            proxy_http_version 1.1;
            proxy_set_header Connection "";
            proxy_redirect off;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass http://wwlproxy;
        }
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
            root html;
        }
    }
}
stream {
    log_format tcplog "$remote_addr [$time_local] $status $session_time $bytes_sent $bytes_received $upstream_addr $upstream_connect_time $connection";
    access_log      logs/stream.log tcplog;
    #upstream wwlconn {
    #        server 255.255.255.255:8080;
    #}长链后端配置请到/home/wwlocal/wwlnginx/conf/tcpconn.conf
    include tcpconn.conf;
    server {
        listen 8080 so_keepalive=30m::10;
        proxy_pass wwlconn;
    }
}
2,/home/wwlocal/wwlnginx/conf/webhost.conf

 

upstream wwlproxy{
        server 192.168.1.10:80 max_fails=10 fail_timeout=1s;
        server 192.168.1.20:80 max_fails=10 fail_timeout=1s;
        server 192.168.1.30:80 max_fails=10 fail_timeout=1s;
        server 192.168.1.10:80 max_fails=0 backup;
        server 192.168.1.20:80 max_fails=0 backup;
        server 192.168.1.30:80 max_fails=0 backup;
        keepalive 128;
}
复制代码

 3.调试 nginx

用到 --with-debug ,待写。

4、如何调试 location#

可以通过在不同 location 里添加 access_log 来调试。

5、如何调试 rewrite#

rewrite_log on; 开启 nginx 日志

设置 error_log 的 level 是 notice

https://www.cnblogs.com/xjnotxj/p/13094290.html

https://www.zhihu.com/question/30255532

 

posted @   littlevigra  阅读(958)  评论(2编辑  收藏  举报
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
· 【译】Visual Studio 中新的强大生产力特性
· 2025年我用 Compose 写了一个 Todo App
历史上的今天:
2019-12-30 使用DBeaver连接pheonix
2019-12-30 vmware 虚拟机损坏后的修复办法(转)
点击右上角即可分享
微信分享提示