本教程将帮助您如何请求重定向到NGINX Web服务器另外一个域名。若是你有计划或更改您的域名,并但愿将流量重定向到旧域名服务器的新域名这是必需的。 首先,编辑您的 nginx 域名配置文件,并添加配置,按您的重定向的要求。php
$ vi /etc/nginx/sites-enabled/mydomain.com.conf
这将全部传入请求重定向域名给url http://anotherdomain.com/dir1/index.php,以下配置。nginx
server { listen 192.168.1.100:80; server_name mydomain.com; return 301 http://anotherdomain.com/dir1/index.php; }
这将在域名中的全部传入的请求重定向到另外一个域名(http://anotherdomain.com/)与相应的请求的URL和查询字符串。服务器
server { listen 192.168.1.100:80; server_name mydomain.com; return 301 http://anotherdomain.com$request_uri; }
这将在域名中的全部传入的请求重定向到另外一个域名(http://anotherdomain.com/)与相应的请求的URL和查询字符串。它也将使用重定向的URL相同的协议。dom
server { listen 192.168.1.100:80; server_name mydomain.com; return 301 $scheme://anotherdomain.com$request_uri; }
作上述更改后,从新启动服务器NGINX从新加载新添加的配置。url