nginx配置集合
只需在需要限制的server里添加如下配置,重载即可
* 获取本地时间
if ( $time_local ~ "^(\d+)\/(\w+)\/(\d+):(\d+):(\d+):(\d+) \+(\d+)" ) {
set $hour $4;
}
* 指定时间黑名单,如果为指定直接,返回500
if ( $hour ~ 00|01|05|06|07 ) {
return 500;
}
* 重定向去除上下文
location /jeecg-boot {
rewrite ^/jeecg-boot/(.*)$ /$1 break;
proxy_pass http://127.0.0.1:18083/jeecg-boot;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 25s;
proxy_send_timeout 25s;
proxy_read_timeout 25s;
proxy_intercept_errors on;
limit_conn_log_level error;
limit_rate_after 200000k;
limit_rate 20000k;
}
* 解决刷新页面404的问题添加
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-5TgaqBVx-1686554992285)(images/2oMIgeMMxgJTalkj0YGPABCofzRARb8_iVLRGWbFVZI.png)]
try_files $uri $uri/ /index.html;
* nginx配置日志保存时间:
新建/etc/logrotate.d/nginx文件并配置:
/usr/local/nginx/logs/access.log {
rotate 26
size 5k
dateext
dateformat -%Y-%m-%d
missingok
compress
sharedscripts
postrotate
test -r /usr/local/nginx/logs/nginx.pid && kill -USR1 `cat /usr/local/nginx/logs/nginx.pid`
endscript
}