1、罕用nginx常用命令
在nginx部署目录:/home/admin/soft/nginx/sbin/下
- 查看 nginx 版本号
./nginx -v - 启动 nginx
./nginx
查看是否启动胜利:ps -ef|grep nginx - 进行 nginx
./nginx -s stop - 从新加载 nginxv
./nginx -s reload - 查看版本号
nginx -v - 查看配置文件是否有误
nginx –t
2、nginx 日志配置不失效的问题
log_format 有个默认的日志格局:
log_format combined '$remote_addr - $remote_user [$time_local] ' ' "$request" $status $body_bytes_sent ' ' "$http_referer" "$http_user_agent" ';
nginx 默认调用 combined 格局来记录日志,即默认调用:(默认记录在access.log文件中)
access_log logs/access.log combined;
nginx容许自定义日志格局,例如:
log_format main '$remote_addr - $remote_user [$time_local] "$http_host" "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" $http_x_forwarded_for $request_time';
以上是自定义了日志格局:main(main名称能够自定义)
要想使其失效,就必须用access_log指定调用:
access_log logs/xx.log main;
否则,nginx依然会去调用combined格局来记录日志。
留神,http段也必须明确指定调用main格局才会失效,否则还是会调用默认的combined格局。
3、打印自定义header
nginx.conf
log_format accesslog '$http_x_forwarded_for`$remote_addr`$proxy_add_x_forwarded_for`[$time_local]`"$request"`' '$status`$body_bytes_sent`"$http_referer"`' '"$http_user_agent"`"$request_time"`' '$request_id`$upstream_response_time`$upstream_addr`$upstream_connect_time`$upstream_status';
在自定义的conf/web.conf 中配置nginx 的server
server{listen 80;server_name _;access_log /home/admin/logs/nginx/web_access.log accesslog;location ~*~/login/{rewrite ^/login/(.*) /$1 break;proxy_pass http://xx.xx.xx.xx;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;}}
注:
header必须用减号“-”分隔单词,nginx外面会转换为对应的下划线“_”连贯的小写单词。
1、nginx是反对读取非nginx规范的用户自定义header的,然而须要在http或者server下开启header的下划线反对:
underscores_in_headers on;
2、比方咱们自定义header为X-Real-IP,通过第二个nginx获取该header时须要这样:
$http_x_real_ip; (一律采纳小写,而且后面多了个http_,减号转成下划线)
参考:
1)https://www.cnblogs.com/hjqjk...
2)http://nginx.org/en/docs/http...