1.屏蔽所有xml请求
location ~ .*\.(xml)$ {return 403;}
2.配置默认维护页面
rewrite ^(.*)$ index.html break;
#页面路径/usr/local/nginx/nginx/html
3强制http转https
rewrite ^(.*)$ https://$host$1 permanent;
4代理配置
location /sysapp{
proxy_pass http://192.168.119.128:8888/sysapp;
}
location /{
root http://192.168.119.128:8888/sysapp;
index /sysapp/user/login;
}
location /cms{
alias /data/html/cms;
}
5.限制http访问方法,只允许GET,POST请求
if ($request_method !~ ^(GET|POST)$ ) {
return 403;
}
6.域名重定向
server { //第一种配置方法
server_name www.old.com;
rewrite ^/(.*)$ http://www.new.com/$1 permanent;
}
server { //第二种配置方法
server_name www.old.com www.new.com;
if ($host = 'www.old.com') {
rewrite ^/(.*)$ http://www.new.com/$1 permanent;
}
}
7中文乱码问题
charset ISO-88509-1;
8限制iframe嵌套
add_header X-Frame-Options SAMEORIGIN;
#只允许被相同域名下的其他页面引用
# DENY 表示该页面不允许在 frame 中展示
# ALLOW-FROM https://example.com/ 表示该页面可以在指定来源的 frame 中展示。
9例子
server {
listen 80;
listen 443 ssl;
ssl on;
server_name www.aaa.com 222.222.222.222;
ssl_certificate /usr/local/nginx/conf/certs/aaa.com.crt;
ssl_certificate_key /usr/local/nginx/conf/certs/aaa.com.key;
ssl_protocols TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4:!DH:!DHE;
ssl_prefer_server_ciphers on;
charset ISO-88509-1;
add_header X-Frame-Options SAMEORIGIN;
location / {
root /data/tomcat/webapps/default;
index index.shtml index.html index.htm;
}
location /app{ proxy_pass http://10.0.1.123:8765/app; }
}
server {
server_name www.old.com;
rewrite ^/(.*)$ https://www.aaa.com/$1 permanent;
}