Welcome! Log In Create A New Profile

Advanced

Nginx rewrite urls to match proxy address

Posted by salimsaid 
Nginx rewrite urls to match proxy address
March 25, 2020 01:19AM
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 ?
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 96
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready