nginx常用配置
1、error_page 不生效
error_page 502 /root/502;
增加 proxy_intercept_errors on;
2、js文件压缩
gzip on;
gzip_types text/plain text/html application/javascript text/css image/x-icon application/wasm
3、增加头
proxy_set_header Accept-Encoding "";
proxy_http_version 1.1;
X-Forwarded-Host www.aaa.com;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
4、防止k8s-ingss过滤掉
proxy_redirect http:// $scheme://;
5、强制443
listen 80;
server_name www.*****.cn;
rewrite ^(.*)$ https://${server_name}$1 permanent;
6、跨域
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE';
add_header 'Access-Control-Allow-Header' 'Content-Type,*';
add_header 'Access-Control-Allow-Credentials' 'true';
7、根据客户端转发
if ($http_user_agent !~* "Android|webOS|iPhone|iPad|iPod|BlackBerry"){
rewrite ^ https://www.abc.com$request_uri? permanent;
}
8、禁止IP访问
server {
listen 80 default_server;
server_name _;
return 403;
}
本文来自博客园,作者:武兴旺,转载请注明原文链接:https://www.cnblogs.com/wuxingwang/p/14516815.html