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 , you want to redirect that domain name to . 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 301$request_uri;