server { listen 80; server_name ngin服务器所对应的的域名; error_log /data/logs/nginx/mainsite.error.log; access_log /data/logs/nginx/mainsite.access.log main; #error_log logs/error.log notice; #error_log logs/error.log info; location ^~ /api/ { // 转发请求路径的 下的 “/api/ ” //设置跨域 add_header Access-Control-Allow-Origin *; add_header Access-Control-Allow-Credentials true; add_header Access-Control-Allow-Headers "Origin, No-Cache, X-Requested-With, If-Modified-Since, Pragma, Last-Modified, Cache-Control, Expires, Content-Type, X-E4M-With"; proxy_pass http://mainsite; //要转发的地址 } error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }