.

Set Up Unmanaged VPS (4 Newbies) – Part 14: Point a Site or Blog at Another

English   English (change)

Set Up Unmanaged VPS (4 Newbies) – Part 14: Point a Site or Blog at Another

nginx rewrite image

This how-to guide shows the syntax to point a site or blog to another domain. That way, for instance, traffic from a passive site benefits an active one.

While the purpose may be different, this is the same code used in Part 12 – *USEFULLY* Park A Spare Domain with Nginx.

Open up or create your website’s virtual host configuration file:-

[sniplet guvSellBox]
[sniplet vpsIndexSell]
[text]sudo nano /usr/local/nginx/sites-available/mydomain.com[/text]

If the redirect is the only purpose for the site, delete or comment out anything else, and add this:-

[text]
server {
listen 80;
server_name www.mydomain.org mydomain.org;
rewrite ^/(.*) http://www.mydomain.com/$1 permanent;
}
[/text]

Nginx Rewrite Rule

  • server { opens up the server block
  • listen 80; tells the server to listen on the default port 80
  • server_name www.mydomain.org mydomain.org; this says to listen out for calls to this site, whether including the www prefix or not
  • rewrite ^/(.*) http://www.anotherDomain.com/$1 permanent; tells Nginx to redirect any such calls to this secondary website
  • } just closes the server block

Thassit.

[sniplet vpsIndex]

.