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 {
    }

}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM