nginx.conf进行如下配置:
listen 80;server_name localhost;location / {root /usr/share/nginx/html;index index.html index.htm;}
#开始配置我们的反向代理 location /XXX/ { # /XXX/ 为ajax接口匹配项 例如接口为: xxx/getConfigproxy_pass http://127.0.0.1:8087;# 测试请求地址为你项目具体请求地址#以下为Ajax中跨域配置项add_header 'Access-Control-Allow-Origin' '*';add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';add_header 'Access-Control-Allow-Headers' '*';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';}location = /50x.html {root /usr/share/nginx/html;}error_page 404 /404.html;error_page 500 502 503 504 /50x.html; }
# nginx操作命令:
#启动 start nginx
#加载配置文件 nginx.exe -s reload
#停止 nginx.exe -s stop