我正在尝试通过 subdomian 对本地主机/文件夹执行基本的 NGINX 反向代理,但很难让它重写我的 Assets +链接。
我的 http://localhost:8080/myapp/工作起来很有魅力,但通过 NGINX + 子域,它在子文件夹 Assets 上失败。
我相信我对 NGINX 的“重写”条款感到困惑。
如何重写发送到客户端浏览器的 HTML 以删除/myapp/上下文?
server {
listen 443 ssl;
server_name app1.domain.com;
location / {
rewrite ^/myapp/(.*) /$1 break; # this line seems to do nothing
proxy_pass http://localhost:8080/myapp/;
}
}
我期望生成的 HTML(通过 https://app1.domain.com)在没有子文件夹/myapp/的情况下被重写,因此当请求 Assets 时,可以找到它们而不是针对 https://app1.domain.com/myapp/assets/ 的 404 .它应该只是 https://app1.domain.com/assets/ (如果我手动去那里他们工作)
--谢谢。
最佳答案
根据 Ivan 的回复,最终确定我的解决方案:
server {
listen 443 ssl;
server_name app1.domain.com;
location / {
sub_filter '/myapp/' '/'; # rewrites HTML strings to remove context
sub_filter_once off; # ensures it loops through the whole HTML (required)
proxy_pass http://localhost:8080/myapp/;
}
}
关于NGINX proxy_pass 重写 Assets uri,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53965499/