用nginx上了个前端项目,踩了路径的坑,记录一下:
server { listen 2077; server_name localhost; location / { root html; index index.html index.htm; } # 例如:你前端的请求路径是这样的 /api/v1/getData # ^~ /api/ 匹配以‘/api/’开头的请求,请求会被拼接成:http://10.10.10.10:8080/v1/getData location ^~ /api/ { proxy_pass http://10.10.10.10:8080/; } # 再如:你前端的请求路径是这样的 /api/v1/getData,与上面的区别在于proxy_pass路径最后没有`/` # ^~ /api/ 匹配以‘/api/’开头的请求,请求会被拼接成:http://10.10.10.10:8080/api/v1/getData #location ^~ /api/ { # proxy_pass http://10.10.10.10:8080; #} error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }