V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
puremaker
V2EX  ›  NGINX

尝试自己配置转发后端请求的时候有个疑问

  •  
  •   puremaker · 10 小时 51 分钟前 · 684 次点击

    首先这个是前端项目页面的配置,没啥问题,

    location / {
            root   /home/party_game/dist; # 访问根目录
            index  index.html index.htm; # 入口文件
            try_files $uri $uri/ /index.html;
        }
    

    然后正常情况转发后端请求应在再写一个 location 拦截,也就是这样

    location /api {
            proxy_pass http://localhost:60101;
        }
    

    看着也没啥问题是吧?但是震惊我的是,我在前端项目和后端项目里配置的请求地址前缀都是 pgApi (例: http://localhost:60101/pgApi/auth/login ),如此我又尝试了把请求拦截换成了

    location /abc {
            proxy_pass http://localhost:60101;
        }
    或者
    location /xxxx {
            proxy_pass http://localhost:60101;
        }
    

    但是 nginx 都能把前端请求正常的转发到后端服务上,这个是为什么呀? 有点无法理解这部分原理,网上也没有搜到比较符合我问题的答案,特来请教

    chenliangngng
        1
    chenliangngng  
       10 小时 27 分钟前
    全配置发下?
    spencerseth44
        2
    spencerseth44  
       8 小时 48 分钟前
    是不是没走下面这个 location ,下面这个带 proxy_pass 的 location 删掉看看正不正常?看看 nginx 的日志里面请求的 path 是什么
    wangxin3
        3
    wangxin3  
       8 小时 6 分钟前
    改完重新加载 nginx 配置没,nginx -s reload
    manami
        4
    manami  
       5 小时 59 分钟前
    配置没生效,楼上说的 reload 试下
    liudewa
        5
    liudewa  
       4 小时 41 分钟前
    日志 里 能看到 转发后的 路径
    关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1274 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 20ms · UTC 17:30 · PVG 01:30 · LAX 10:30 · JFK 13:30
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.