假设两个域名 cai.com www.cai.com,需要把所有cai.com 的访问都跳转到 www.cai.com
server {
listen 80 ;
server_name _;
index index.html index.htm index.php;
root /alidata/www/;
location ~ .*\.(php|php5)?$
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 1h;
}
access_log /alidata/log/nginx/access/default.log;
}
server {
listen 80 default;
server_name www.cai.com;
index index.html index.htm index.php;
root /alidata/www/114/trunk/;
location ~ .*\.(php|php5)?$
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 1h;
}
access_log /alidata/log/nginx/access/114.log;
}
server {
server_name cai.com;
rewrite "^/(.*)" http://www.cai.com/$1 permanent;
}