linuxsteam
V2EX  ›  问与答

求指点一个 nginx 反代规则~

  •  
  •   linuxsteam · Jun 28, 2020 · 1253 views
    This topic created in 2147 days ago, the information mentioned may be changed or developed.

    我的后端 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 replies    2020-07-16 08:05:05 +08:00
    linuxsteam
        1
    linuxsteam  
    OP
       Jun 28, 2020
    求助呀~难啊
    AstroProfundis
        2
    AstroProfundis  
       Jun 28, 2020
    proxy_pass https://api.domain.cn/meta/type/attachment/;

    改成

    proxy_pass https://api.domain.cn;

    默认是带上了 uri 的,这类问题应该先看后端 404 的日志怎么说,应该就能发现 uri 不对了
    ik
        3
    ik  
       Jun 28, 2020 via iPhone
    补充 #2
    proxy_set_header Host api.domain.cn;
    linuxsteam
        4
    linuxsteam  
    OP
       Jul 16, 2020
    谢谢楼上的,
    找到问题原因了,反代 SSL 网站,本地也需要设置一个证书
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   896 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 53ms · UTC 20:31 · PVG 04:31 · LAX 13:31 · JFK 16:31
    ♥ Do have faith in what you're doing.