Proxy的Error_page配置
- 使用proxy之后,想要用nginx统一管理错误页,在http模块中增加
proxy_intercept_errors on;
- 然后,在server中增加:
error_page 404 = /error/404.html;
error_page 500 502 503 504 = /error/50x.html;
location /error/ {
root html;
}
- location模块中配置的root html,直接用的是nginx安装目录之下的html目录
Proxy_Cache缓存
- 使用缓存,在http模块中增加(我是在windows中配置的,E:/temp/cache是在nginx安装目录之下)
proxy_cache_path E:/temp/cache levels=1:2 keys_zone=imgcache:100m inactive=1d max_size=1g;
- 然后在location模块中增加
log_not_found off;
access_log off;
expires 7d;
proxy_cache imgcache;
proxy_cache_valid 200 302 1d;
proxy_cache_valid 404 10m;
proxy_cache_valid any 1h;
proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;
- 关键就是keys_zone配置的imgcache和location模块中的proxy_cache对应上,重启后,访问页面,正常情况下,会在/temp/cache中生成缓存文件
正则配置Location,匹配目录的参数传递
- 正则配置location的参数传递配置
location ~*(/dabing-portal)?/(.*)$ {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Cookie $http_cookie;
proxy_pass http://tomcat83/dabing-portal/$2?$args;
proxy_connect_timeout 1;
proxy_read_timeout 1;
proxy_send_timeout 1;
日志分割
- Nginx没有找到找到日志分割功能,网上找的bat脚本,使用windows计划任务即可
taskkill /F /IM nginx.exe
set logDir=E:\Web\nginx-1.9.12\logs
set "cmdstr=move %logDir%\access.log %logDir%\accessLog\access_%date:~0,4%-%date:~5,2%-%date:~8,2%.log
call %cmdstr%"
start nginx