V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
linuxsteam
V2EX  ›  问与答

求指点一个 nginx 反代规则~

  •  
  •   linuxsteam · 2020-06-28 14:09:50 +08:00 · 833 次点击
    这是一个创建于 1369 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我的后端 https://api.domain.cn/meta/type/files/1 (java 读取本地图片输出的 response) 我的想达到访问 https://domain.cn/meta/type/files/1 就是访问我后端 https://api.domain.cn/meta/type/files/1

    下面的配置不好用,访问就是 404,是我理解错 nginx 的反代了吗

    location / {
    		# nuxt 项目
            proxy_pass http://127.0.0.1:3000/;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
            add_header X-Cache $upstream_cache_status;
            add_header Cache-Control no-cache;
    }                                                     
    location /meta/type/attachment/ {
    		# 我的 java 后端
            proxy_pass https://api.domain.cn/meta/type/attachment/;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
            add_header X-Cache $upstream_cache_status;
            add_header Cache-Control no-cache;               
    }      
    
    4 条回复    2020-07-16 08:05:05 +08:00
    linuxsteam
        1
    linuxsteam  
    OP
       2020-06-28 16:14:40 +08:00
    求助呀~难啊
    AstroProfundis
        2
    AstroProfundis  
       2020-06-28 16:38:01 +08:00
    proxy_pass https://api.domain.cn/meta/type/attachment/;

    改成

    proxy_pass https://api.domain.cn;

    默认是带上了 uri 的,这类问题应该先看后端 404 的日志怎么说,应该就能发现 uri 不对了
    ik
        3
    ik  
       2020-06-28 17:03:54 +08:00 via iPhone
    补充 #2
    proxy_set_header Host api.domain.cn;
    linuxsteam
        4
    linuxsteam  
    OP
       2020-07-16 08:05:05 +08:00
    谢谢楼上的,
    找到问题原因了,反代 SSL 网站,本地也需要设置一个证书
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1129 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 18:46 · PVG 02:46 · LAX 11:46 · JFK 14:46
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.