简体   繁体   中英

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.

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. 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 .

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

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,

I need nginx to rewrite all my links in localhost:8000/* to proxy.site/* , no body loves typing ports when accessing a blog,

Here is how my nginx conf file looks like

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 ?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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