nginx配置总结
1、跨域处理
location / { add_header Access-Control-Allow-Origin *; add_header Access-Control-Allow-Credentials true; ##可选 add_header Access-Control-Request-Headers custom-Key;//添加自定义请求头 add_header Access-Control-Allow-Headers DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization; add_header Access-Control-Allow-Methods GET,POST,OPTIONS; if ($request_method='OPTIONS'){ return 204; } }
2、跳转到https
server{ listen 80; server_name localhost; rewrite ^(.*) https://$host$1 permanent; ##跳转到https; }
3、禁用缓存
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css)$ { #禁止缓存,每次都从服务器请求 add_header Cache-Control no-store; }