配置虛擬主機,接受 Host 首部與 *.dddxxx.com 匹配的請求赖淤。
判斷 HTTP 請求的 HOST 首部,如果不是 dddxxx.com 或者 www.dddxxx.com,則進行重定向到 dddxxx.com
通過設(shè)置變量到達條件組合的效果。
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;
}
}