配置虚拟主机,接受 Host 首部与 *.dddxxx.com 匹配的请求。
判断 HTTP 请求的 HOST 首部,如果不是 dddxxx.com 或者 www.dddxxx.com,则进行重定向到 dddxxx.com
通过设置变量到达条件组合的效果。
server {
listen 80;
server_name dddxxx.com www.dddxxx.com *.dddxxx.com;
root /var/www/html/dddxxx.com;
access_log /var/log/nginx/dddxxx.com.access_log.log;
set $myhost '';
if ($host = 'dddxxx.com') {
set $myhost 1;
}
if ($host = 'www.dddxxx.com') {
set $myhost 1;
}
if ($myhost != 1) {
rewrite ^/(.*)$ http://dddxxx.com/$1 permanent;
}
location / {
try_files $uri $uri/ =404;
}
}