#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; underscores_in_headers on; #nginx消除header 里-的问题 #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #gzip_static开启 默认加载gzip结尾的文件 gzip on; gzip_static on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.1; gzip_comp_level 2; gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml; gzip_vary on; gzip_proxied expired no-cache no-store private auth; gzip_disable "MSIE [1-6]\."; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { listen 80; server_name localhost; rewrite ^(.*)$ https://$host$1 permanent; #把http的域名请求转成https } # HTTPS server server { listen 443 ssl; server_name wwww.xxxxx.com; ssl_certificate /usr/local/nginxj/a.pem; ssl_certificate_key /usr/local/b.key; ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; location /api/ { if ($request_method = 'OPTIONS') { add_header 'Access-Control-Allow-Origin' '*'; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range'; add_header 'Access-Control-Max-Age' 1728000; add_header 'Content-Type' 'text/plain; charset=utf-8'; add_header 'Content-Length' 0; return 204; } if ($request_method = 'POST') { add_header 'Access-Control-Allow-Origin' '*'; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range'; add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range'; } if ($request_method = 'GET') { add_header 'Access-Control-Allow-Origin' '*'; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range'; add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range'; } rewrite "^/api/(.*)$" /$1 break; proxy_pass http://localhost:8080/; } location /admin { # alias结尾记得添加/ alias /usr/local/xxx/admin/; index index.html index.htm; if (!-e $request_filename) { # 此处是重点,如果有配置根域名,且前端未做跳转配置,则下方rewrite也需要携带根域名 否则会出现刷新404 rewrite ^/(.*) /admin/index.html last; break; } } location / { add_header Cache-Control no-store; alias /usr/local/xxx/front/; index index.html index.htm; if (!-e $request_filename) { # 此处是重点,如果有配置根域名,且前端未做跳转配置,则下方rewrite也需要携带根域名 否则会出现刷新404 rewrite ^/(.*) /index.html last; break; } } location /wb_df9ff20ea541968f.txt { root /usr/local/xxx/; } location /MP_verify_u3ohQNDHVylfuKHB.txt { root /usr/local/xxx/; } location /apple-app-site-association { include mime.types; default_type application/json; root /usr/local/xxx/; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }