Nginx重定向配置
所有非www二级域名都跳转到www.c n.com下去。
-
#所有非www. cn.com开始的域名,都重定向到www.c n.com下去。 -
if ($http_host !~ "^www.cn .com$") { -
rewrite ^(.*) https://www. cn.com$1 permanent; -
}
一级域名跳转到www二级域名下面去。
-
#只是一级域名“c n.com” 跳转到www.c n.com去。 -
if ($http_host ~ "^c n.com$") { -
rewrite ^(.*) https://www.c n.com$1 permanent; -
}
Nginx config配置位置参考:
-
-
server{ -
listen 80; -
server_name www.c n.com admin.c n.com csdn.com; -
index index.html; -
access_log syslog:server=127.0.0.1,facility=local6,tag=nginxlog_access,severity=notice main; -
error_log syslog:server=127.0.0.1,facility=local6,tag=nginxlog_error; -
-
#我在这里 -
if ($http_host ~ "^csdn.com$") { -
rewrite ^(.*) https://www.c n.com$1 permanent; -
} -
-
location ~* ^.+\.(ico|gif|jpg|jpeg|png)$ { -
access_log off; -
expires 7d; -
} -
location ~* \/(sitemap|robots)\.(html|txt|xml|xsl)$ { -
root /data/www/c n.com/sitemap; -
} -
location / { -
proxy_set_header Host $host; -
proxy_set_header X-Real-IP $remote_addr; -
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; -
-
if ($host ~* www\.csdn\.com) { -
proxy_pass https://www.c n.com:8888; -
} -
if ($host ~* admin\.c n\.com) { -
proxy_pass http://admin.c n.com:8888; -
} -
-
}