先说要点,再show code
1,nginx转发不要填写127.0.0.1,localhost等ip地址
2,location根路径要加try_file选项,请求转发到index.html
3,如果有path有/,那就都带上/
我的nginx.conf
#user root; worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { listen 8081; server_name localhost; root C:\Users\Administrator\Documents\s-ui\dist; index index.html index.htm; location /prod-api/ { proxy_http_version 1.1; proxy_set_header Connection ""; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $remote_addr; proxy_pass http://192.168.8.100:8080/; } location / { add_header 'Access-Control-Allow-Origin' '*'; try_files $uri $uri/ /index.html; #匹配项目的入口页,前面必须加/ } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }
标签:npm,index,vue,set,端口,header,html,proxy,location From: https://www.cnblogs.com/difs/p/18059324