繁体   English   中英

Nginx 重写 url 以匹配代理地址

[英]Nginx rewrite urls to match proxy address

我正在运行一个 wordpress docker 容器,该站点可通过主机端口8000访问,如果转到 localhost:8000 繁荣,我将看到我的 wordpress 站点。

总是输入localhost:8000来查看我的网站很无聊,所以我决定委托 nginx 作为我网站的反向代理。 我已经在 nginx 中设置了一个名为proxy.site的虚拟主机,我现在可以通过访问http://proxy.site来访问 wordpress 站点。

到目前为止,我们做得很好,当http://proxy.site打开时,我可以看到我的博客文章列表,假设我想阅读关于 COVID-19 的最新博客文章,当我点击链接,ohohohoho 它打开为http://localhost:8000/posts/covid19

我希望它以http://proxy.site/posts/covid19的代理 url 打开,我需要通过http://proxy.site站点名称访问整个站点,

我需要 nginx 将我在localhost:8000/*所有链接重写为proxy.site/* ,没有人喜欢在访问博客时输入端口,

这是我的 nginx conf 文件的样子

server {
        listen 80;
        listen [::]:80;

        root /var/www/proxy.site/html;
        index index.html index.htm index.nginx-debian.html;

        server_name proxy.site www.proxy.site;

        location / {
                proxy_pass http://localhost:8000;
                #proxy_set_header HOST $host;
                #proxy_redirect http://localhost:8000/ http://proxy.site/ ;
                #try_files $uri $uri/ =404;
        }
}

如何使用自定义主机名重写代理站点中的所有 url?

Nginx 不听 localhost:8080,Nginx 不会检查来自您站点的链接来重写它们,您应该在 WordPress 上找到一种方法来替换您的链接的基本 url。基于环境

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM