Oli*_*ver 3 rewrite nginx domain subdomain
这是一个相当快的:如何重定向到另一个域并仍然转发子域?示例:http : //foo.domainone.com/bar.php -> http://foo.domaintwo.com/bar.php
提前致谢!
小智 7
以下内容应该对您有用(这会将 test.com 重定向到 abc.com):
server {
# Listen on ipv4 and ipv6 for requests
listen 80;
listen [::]:80;
# Listen for requests on all subdomains and the naked domain
server_name test.com *.test.com;
# Check if this is a subdomain request rather than on the naked domain
if ($http_host ~ (.*)\.test\.com) {
# Yank the subdomain from the regex match above
set $subdomain $1;
# Handle the subdomain redirect
rewrite ^ http://$subdomain.abc.com$request_uri permanent;
break;
}
# Handle the naked domain redirect
rewrite ^ http://abc.com$request_uri permanent;
}
Run Code Online (Sandbox Code Playgroud)
这应该确保裸域和任何子(或子、子)域被重定向到新的“基本”域。实践中的一些例子:
phoenix:~ damian$ curl -I -H "Host: test.com" web1-france
HTTP/1.1 301 Moved Permanently
Server: nginx/1.1.1
Date: Sat, 08 Oct 2011 06:43:45 GMT
Content-Type: text/html
Content-Length: 160
Connection: keep-alive
Location: http://abc.com/
phoenix:~ damian$ curl -I -H "Host: subdomain1.test.com" web1-france
HTTP/1.1 301 Moved Permanently
Server: nginx/1.1.1
Date: Sat, 08 Oct 2011 06:43:50 GMT
Content-Type: text/html
Content-Length: 160
Connection: keep-alive
Location: http://subdomain1.abc.com/
phoenix:~ damian$ curl -I -H "Host: wibble.subdomain1.test.com" web1-france
HTTP/1.1 301 Moved Permanently
Server: nginx/1.1.1
Date: Sat, 08 Oct 2011 06:43:55 GMT
Content-Type: text/html
Content-Length: 160
Connection: keep-alive
Location: http://wibble.subdomain1.abc.com/
Run Code Online (Sandbox Code Playgroud)
在重写行上,您可以指定“last”而不是“permanent”以获得 302 Moved Temporously 而不是 301 Moved Permanently。如果您要移动域,那么您应该选择后者:)
希望这可以帮助。
| 归档时间: |
|
| 查看次数: |
5482 次 |
| 最近记录: |