首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >修复nginx sub_filter?

修复nginx sub_filter?
EN

Stack Overflow用户
提问于 2022-06-22 06:28:35
回答 1查看 46关注 0票数 1

我正试图修复我的反向代理背后的一个行为不端的应用程序--基本上,它会将绝对URL放到页面中。

我的公寓看起来就像

代码语言:javascript
运行
复制
...

location /openproject/ {
    proxy_set_header Host <internal host>;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass http://<internal host>/openproject/;

    sub_filter 'http:<internal url>' 'https:<external url>';
    sub_filter_once on;
    sub_filter_last_modified on;
}
...

<>中的东西被替换以保护我的主机。没错,行为不端的应用程序是OpenProject。

它似乎不起作用,调试也没有提到任何关于替换发生的事情。

我做错什么了吗?

nginx -V

TLS nginx版本: nginx/1.18.0构建于2021年3月25日(运行于2022年5月3日的-ffile-prefix-map=/build/nginx-q9LD4J/nginx-1.18.0=. 1.1.1o ),它支持启用配置参数:- with =‘-g -O2 OpenSSL-fstack现在前缀=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf -http-log-path=/var/log/nginx/access.log.log-path=/var/log/nginx/error.log-path=/var/lock/nginx.lock-pid-path=/run/nginx.pid-模块-path=/usr/lib/nginx/ --http-client-body-temp-path=/var/lib/nginx/body -http-temp-path=/var/lib/nginx/快速scgi http-代理-temp-path=/var/lib/nginx/代理-http-scgi-temp-path=/var/lib/nginx/scgi-http-uwsgi-temp-path=/var/lib/nginx/uwsgi with-compat-with-pcre-jit-with-http_ssl_module with-http_stub_status_module with-http_realip_module with-_auth_request_module --具有-http_v2_模块-与-http_dav_模块-与-http_片_模块-带有-http_sub_模块-具有-http_gunzip_模块-with-http_gzip_static_-with_gzip_static_

EN

回答 1

Stack Overflow用户

发布于 2022-06-28 00:01:19

找到这个https://marsbard.github.io/2016-07-30-replace-urls-behind-nginx-reverse-proxy/

似乎我需要的配置是:

代码语言:javascript
运行
复制
location /openproject/ {

        proxy_set_header Accept-Encoding ""; # no compression allowed or next won't work

        sub_filter "http://<internal host>/" "https://<external host>/";
        sub_filter_once off;

        proxy_set_header Host <internal 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-Host $host:$server_port;

        proxy_pass http://<internal host>/openproject/;

}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72710633

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档