zoukankan      html  css  js  c++  java
  • 配置文件 proxy_set_header -发往后端服务器的请求头---- nginx日志调试技巧

    server {
        listen 80;
        server_name  paas.service.consul;
    
        client_max_body_size    512m;
        access_log  /data/bkdata/bkce/logs/nginx/paas_inner_access.log;
    
        # ============================ paas ============================
        # PAAS_SERVICE HOST/PORT
    
       
     location ~ ^/login/(.*) {
            proxy_pass http://OPEN_PAAS_LOGIN/$1$is_args$args;
            proxy_pass_header Server;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Scheme $scheme;
            proxy_set_header Host $http_host;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_set_header X-Forwarded-Host $http_host;
            proxy_redirect off;
            proxy_read_timeout 600;
        }
    #user  root;
    worker_processes  auto;
    
    error_log  /usr/local/var/log/nginx/error.log;
    #pid        logs/nginx.pid;
    
    
    events {
        worker_connections  1024;
    }
    
    http {
        include       mime.types;
        default_type  application/octet-stream;
        #default_type text/html;
    
        client_max_body_size 2G;
        server_names_hash_bucket_size 256;
    
        sendfile        on;
    
        keepalive_timeout  65;
    
        log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"' '$upstream_addr $upstream_response_time $request_time '; 
    access_log logs/access.log main;
    underscores_in_headers on; include /usr/local/etc/nginx/conf.d/*.conf; }

    参考:https://www.cnblogs.com/biglittleant/p/8979856.html

     2.长连接需要配置

     proxy_http_version 1.1;

    proxy_set_header Connection "";  #如果没加,后端服务器会收到 Connection: close 的 Header,而不能复用连接; 清空connection的请求头,避免客户端传递短链接的请求头信息。

    https://www.jianshu.com/p/fd16b3d10752

    1.调试rewrite规则

    调试rewrite规则时,如果规则写错只会看见一个404页面,可以在配置文件中开启nginx rewrite日志,进行调试。

    server {
            error_log    /var/logs/nginx/example.com.error.log;
            rewrite_log on;
    }

    rewrite_log on; 开启后,它将发送所有的 rewrite 相关的日志信息到 error_log 文件中,使用 [notice] 级别。随后就可以在error_log 查看rewrite信息了。

    2.使用location记录指定URL的日志

    server {
            error_log    /var/logs/nginx/example.com.error.log;
            location /static/ { 
            error_log /var/logs/nginx/static-error.log debug; 
        }         
    }

    配置以上配置后,/static/ 相关的日志会被单独记录在static-error.log文件中。

    nginx日志共三个参数
    access_log: 定义日志的路径及格式。
    log_format: 定义日志的模板。
    open_log_file_cache: 定义日志文件缓存。

    proxy_set_header X-Forwarded-For :如果后端Web服务器上的程序需要获取用户IP,从该Header头获取。proxy_set_header X-Forwarded-For $remote_addr;

    https://www.cnblogs.com/biglittleant/p/8979856.html

  • 相关阅读:
    DML和DQL语句
    MYSQL创建用户和授权方法(测试mysql5.7)
    安卓ViewPager中Button点击事件弹出Dialog
    安卓从popupwindow跳转到Activity页面
    Collect preferences failed, class java/lang/AutoCloseable not found in D:Program Files (x86)Androidandroid-sdkplatformsandroid-19android.jar
    安卓横屏布局设置
    C#控制台程序自动重启(检测是否连接网络)
    C++指针学习
    C++共享数据的保护
    C++结构体再学心得
  • 原文地址:https://www.cnblogs.com/hixiaowei/p/10915417.html
Copyright © 2011-2022 走看看