nginx+tomcat把带WWW域名自动跳转到不带www域名方法

nginx+tomcat把带WWW域名自动跳转到不带www域名方法
在nginx.conf里面 include /etc/nginx/conf.d/*.conf;
在应该server里增加:
if ($http_host !~ "^xxx.com") {
rewrite /.* http://xxx.com$uri permanent;
}
注意:!~ "^xxx.com" 这个xxx是你的域名,不用在前面带www.的


server_name xxx.com www.xxx.com;
access_log /var/log/nginx/access_shichuannet.com.log;
error_log /var/log/nginx/error_shichuannet.com.log;

日志代码放在server_name下,上面的if语句放在日志下面

其他二级域名使用另外的server,不受这个跳转的影响

------------------------------
apache的.htaccess代码
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.\.me$ [NC]
RewriteRule ^(.*)$ http://googlo.me/$1 [L,R=301]
------------------------

 

server {
    listen       80;
    server_name  zdz8207.com www.zdz8207.com;
    access_log  /var/log/nginx/access_shichuannet.com.log;
    error_log  /var/log/nginx/error_shichuannet.com.log;
    
    if ($http_host !~ "^zdz8207.com") {
         rewrite /.* http://zdz8207.com$uri permanent;
    }
    
    location / {
        client_max_body_size    10m;
        index  index.html index.htm index.jsp;
        proxy_set_header Host $host;
        proxy_pass_header User-Agent;
        proxy_pass http://localhost:8089/;
    }


    error_page 404 /404.html;
        location = /40x.html {
    }

    error_page 500 502 503 504 /50x.html;
        location = /50x.html {
    }

}

 

posted @ 2017-01-20 18:51  大自然的流风  阅读(5977)  评论(0编辑  收藏  举报