当前位置:   article > 正文

nginx 作为vue项目服务器简单配置_vue nginx配置

vue nginx配置
  1. server {
  2. listen 80; #监听80端口
  3. server_name localhost;
  4. location / {
  5. root /xxxx/xxx/xxx; #你项目在系统中的路径
  6. index index.html index.htm;
  7. }
  8. }

一个简单配置就玩了。

我这个项目有个特殊的地方,一个项目用了两个后台,请求的地址就不一样,我是根据前端请求uri区别使用那个后端的。比如浏览器http://localhost/system/user/list就使用 localhost:8080后台,如果是http://localhost/business/xxxx就使用localhost:8081后台,nginx配置如下:

  1. server {
  2. listen 80; #监听80端口
  3. server_name localhost;
  4. location / {
  5. root /xxxx/xxx/xxx; #你项目在系统中的路径
  6. index index.html index.htm;
  7. }
  8. location /system {
  9. proxy_pass http://localhost:8080;
  10. }
  11. location /business {
  12. proxy_pass http://localhost:8081;
  13. }
  14. }

 重点重点重点:  在配每一个跳转时(/system)  proxy_pass后面地址结尾是否带斜杠"/"是不一样的.

情况1  proxy_pass http://localhost:8081/; 结尾有斜杠

我请求/business/order/list 这个时, 最终跳转的是 http://localhost:8081/order/list 不会把locahost后面匹配的字符串加到请求里

情况2  proxy_pass http://localhost:8081; 结尾没有斜杠

我请求/business/order/list 这个时, 最终跳转的是 http://localhost:8081/business/order/list .

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/232361
推荐阅读
相关标签
  

闽ICP备14008679号