https强跳
server {
listen 80;
server_name www.xxxxx.com;
rewrite ^/(.*)$ https://$host/$1 permanent;
}
证书配置和配置优化
ssl on;
ssl_certificate ca/server.pem;
ssl_certificate_key ca/server.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!RC4:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!EXP:+MEDIUM;
ssl_prefer_server_ciphers on;
add_header X-Content-Type-Options "nosniff"; #关闭IE的文档类型自动判断可用于IE8+
和Chrome
。
add_header X-XSS-Protection "1; mode=block"; #用于防范及过滤XSS
add_header X-Frame-Options SAMEORIGIN; #是否允许浏览器加载frame
、iframe
、object
等属性
add_header Strict-Transport-Security "max-age=63072000; includeSubdomains" always; #用于标识浏览器用HTTPS
替代HTTP
的方式去访问目标站点
add_header Pragma no-cache; #不缓存静态文件
静态文件访问
location / {
root /data/www/dist;
index $CustomHtml index.html;
try_files $uri /$CustomHtml /index.html =404;
}
反向代理访问
location ^~ /api {
access_log logs/api-access.log main;
proxy_pass http://api;
proxy_redirect off ;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
状态监测
server {
listen 801;
server_name 127.0.0.1;
access_log off;location /webstatus {
stub_status on;
allow 127.0.0.1;
deny all;
}location /status{
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
allow 127.0.0.1;
deny all;
}
}
socket5端口代理
stream{
upstream socket_server{
server 127.0.0.1:3802 weight=1;#发布socket1服务端口
server 127.0.0.1:3803 weight=1;#发布socket2服务端口
}
#监听socket端口
server {
listen 3801;
proxy_pass socket_server;
}
转发给php
location / {
index index.html index.php;
try_files $uri $uri/ /index.php?$args;
}location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
多域名跨域配置
map域名配置文件map.conf
map $http_origin $corsHost {
default 0;
"~http://pincode.admin.modules.snsshop.net" http://pincode.admin.modules.snsshop.net;
"~http://pincode.weixin.modules.snsshop.net" http://pincode.weixin.modules.snsshop.net;
"~http://shimao.wx.snsshop.net" http://shimao.wx.snsshop.net;
"~http://shake.admin.modules.snsshop.net" http://shake.admin.modules.snsshop.net;
"~http://shake.weixin.modules.snsshop.net" http://shake.weixin.modules.snsshop.net;
"~http://shake.modules.snsshop.net" http://shake.modules.snsshop.net;
"~http://weiqufang.vikduo.weixin.zhsqbeta.snsshop.net" http://weiqufang.vikduo.weixin.zhsqbeta.snsshop.net;
"~http://shimaoshake.admin.modules.snsshop.net" http://shimaoshake.admin.modules.snsshop.net;
"~http://shimaoshake.weixin.modules.snsshop.net" http://shimaoshake.weixin.modules.snsshop.net;
"~http://weiqufang.vikduo.weixin.zhsqbeta.snsshop.net" http://weiqufang.vikduo.weixin.zhsqbeta.snsshop.net;
"~http://shimao.admin.snsshop.net" http://shimao.admin.snsshop.net;
}在server段内加上:
add_header 'Access-Control-Allow-Origin' $corsHost;
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,X_Requested_With,If-Modified-Since,Cache-Control,Content-Type';
add_header 'Access-Control-Expose-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';