nginx set指令
[root@localhost conf.d]# vim /etc/nginx/conf.d/rewrite.conf
server {
listen 80;
server_name www.rewrite.com rewrite.com;
access_log /var/log/nginx/test2-access.log main;
error_log /var/log/nginx/test2-error.log;
location /{
root /html/rewrite;
index index.html index.htm index.php;
if ($host ~* "^www.rewrite.com$|^rewrite.com$" ) {
break;
}
if ($host ~* "^(.*)\.rewrite\.com$" ) {
set $user $1;
rewrite .* http://www.rewrite.com/$user permanent;
}
}
location /one{
root /html/rewrite;
index index.html index.htm index.php;
}
location /two{
root /html/rewrite;
index index.html index.htm index.php;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/test;
}
}
[root@localhost conf.d]# tree /html
/html
└── rewrite
├── index.html
├── one
│ └── index.html
└── two
└── index.html