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;
}
posted @ 2021-03-11 11:29  武兴旺  阅读(142)  评论(0编辑  收藏  举报