配置文件 proxy_set_header -发往后端服务器的请求头---- nginx日志设置级别调试技巧 - 长连接配置
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
server_tokens off;
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 ';
参考: https://www.cnblogs.com/biglittleant/p/8979856.html
---------------------------------------------------------- 经典日志设置级别--得到关键情报
2、访问日志
[Access.log]
log_format main '$remote_addr r e m o t e u s e r [ remote_user [remoteuser[time_local] “$request” $http_host ’
'$status $upstream_status b o d y b y t e s s e n t " body_bytes_sent "bodybytessent"http_referer" ’
'"$http_user_agent" $ssl_protocol $ssl_cipher $upstream_addr ’
‘$request_time $upstream_response_time’;
https://blog.csdn.net/Hanmin_hm/article/details/104633638
---------------------------------------------------------- 经典日志设置级别--得到关键情报
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$request_time $request_length '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent"';
access_log /var/logs/nginx/access.log main;
keepalive_timeout 0;
参考: https://help.aliyun.com/document_detail/28988.html?spm=a2c4g.11186623.2.12.7a8018ceN8PjJk#reference-kv2-sr5-vdb
---------------------------------------------------------- 经典日志设置级别--得到关键情报
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;