配置文件 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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM