nginx配置www跳转

本文共有1040个字,关键词:

问题:需要设置网站带www的网址www.xiaomantu.com跳转到it.xiaomantu.com(不带www的网址跳转同理)

解决:配置nginx配置文件

方法:
打开nginx的配置文件,我这边是多个网站的配置,所以是vhost下面的xiaomantu.conf文件,修改配置信息,如下

server {
    listen       80;
    server_name  xiaomantu.com www.xiaomantu.com it.xiaomantu.com;
    index index.html index.htm index.php;
    root /alidata/www/xiaomantu;
    if ($host = 'www.xiaomantu.com'){
        rewrite ^/(.*)$ http://it.xiaomantu.com/$1 permanent;
    }
    location ~ .*.(php|php5)?$ {
        #fastcgi_pass  unix:/tmp/php-cgi.sock;
        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/xiaomantu.log;
        error_page 404  /404.html;
}

这样就能保证带 www 的网址跳转到 it 的网址

版权声明:本文为作者原创,如需转载须联系作者本人同意,未经作者本人同意不得擅自转载。
添加新评论
暂无评论