nginx: Redirect from one domain to another

Practice



To set up a redirect (forwarding) from one domain to another via the nginx web server - let's add the following lines to the configuration file, in the domain settings section:

server {
...
listen IP:80;
server_name source_domain.ru;
rewrite ^ http://target_domain.ru$request_uri;
...
}

or another method (using location):

server {
...
listen IP:80;
server_name source_domain.ru;
location = / { rewrite ^ http://target_domain.ru/; }
...
}


here, instead of source_domain.ru, substitute the name of the domain to redirect from, and instead of target_domain.ru - the name of the domain to redirect to.

Applies to: nginx

Comments

To leave a comment

If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Lectures and tutorial on "Running server side scripts using PHP as an example (LAMP)"

Terms: Running server side scripts using PHP as an example (LAMP)