小编a.b*_*eri的帖子

如何使用 nginx 反向代理正确处理相对 url

当然,我不是第一个尝试从 为域提供服务example.com的人example.net/bbb,但我还没有找到解决方案。

我的 NGINX 配置遵循指导方针,看起来像这样:

server {
    listen 80;
    server_name example.net;
    root /path/to/aaa;

    location /bbb/ {
        proxy_pass http://example.com/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }

    location / {
        try_files $uri $uri/ /index.html;
    }
    location ~ \.(svg|ttf|js|css|svgz|eot|otf|woff|jpg|jpeg|gif|png|ico)$ {
        access_log off;
        log_not_found off;
        expires max;
    }
}
Run Code Online (Sandbox Code Playgroud)

我可以设法渲染example.comin的根,example.net/bbb但是:

问题 1

example.net/bbb/some/path预期和不工作index.htmlexample.net呈现。

问题 2

中的任何资产example.com/assets都会给出 404,因为浏览器会查找example.net/assets. 如果我能在不到处放置绝对路径的情况下解决这个问题,那就太好了。

nginx reverse-proxy proxypass

22
推荐指数
1
解决办法
4万
查看次数

标签 统计

nginx ×1

proxypass ×1

reverse-proxy ×1