How to redirect from one domain name to another in nginx web server

Sometimes you want to redirect your domain name to some other domain name. For example, you have http://somedomain.com , you want to redirect that domain name to http://someotherdomain.com . We will show you how to do that from nginx configuration file. (e.g, nginx.conf file).

Requirements: Nginx web server, text editor.

Open your nginx configuration file.  Change your code as shown in the code below.

server {
listen 80;

return 301http://someotherdomain.com$request_uri;
}