本教程將幫助您如何請求重定向到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