简体   繁体   English

Nginx 重写 url 以匹配代理地址

[英]Nginx rewrite urls to match proxy address

I am running a wordpress docker container , the site is accessible through host machines port 8000 , if go to localhost:8000 boom i get to see my wordpress site.我正在运行一个 wordpress docker 容器,该站点可通过主机端口8000访问,如果转到 localhost:8000 繁荣,我将看到我的 wordpress 站点。

It's boring to always type localhost:8000 to see my website, so i decided to commission nginx as a reverse proxy for my site.总是输入localhost:8000来查看我的网站很无聊,所以我决定委托 nginx 作为我网站的反向代理。 I've set up a virtual host in nginx that has the name proxy.site , i can now access by wordpress site by visiting http://proxy.site .我已经在 nginx 中设置了一个名为proxy.site的虚拟主机,我现在可以通过访问http://proxy.site来访问 wordpress 站点。

Up until this point, we are doing great, when http://proxy.site opens up, i can see a list of my blog posts, lets say i want to read my latest blog post about COVID-19 , when i click on the link, ohohohoho it opens up as http://localhost:8000/posts/covid19到目前为止,我们做得很好,当http://proxy.site打开时,我可以看到我的博客文章列表,假设我想阅读关于 COVID-19 的最新博客文章,当我点击链接,ohohohoho 它打开为http://localhost:8000/posts/covid19

I want it to open with the proxy url as in http://proxy.site/posts/covid19 , i need to whole site to be accessible through the http://proxy.site site name,我希望它以http://proxy.site/posts/covid19的代理 url 打开,我需要通过http://proxy.site站点名称访问整个站点,

I need nginx to rewrite all my links in localhost:8000/* to proxy.site/* , no body loves typing ports when accessing a blog,我需要 nginx 将我在localhost:8000/*所有链接重写为proxy.site/* ,没有人喜欢在访问博客时输入端口,

Here is how my nginx conf file looks like这是我的 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;
        }
}

How do i achieve rewrite all urls in the proxied site with my custom host name ?如何使用自定义主机名重写代理站点中的所有 url?

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

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

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