zoukankan      html  css  js  c++  java
  • 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 {
        }
    
    }
  • 相关阅读:
    spring相关资源
    spring mvc获取request HttpServletRequest
    spring中文乱码问题
    haskell读写文件相关(含二进制)
    grade web的构建约定 convention
    李洪强iOS开发之-实现点击单行View显示和隐藏Cell
    Animated progress view with CAGradientLayer(带翻译)
    关于CAShapeLayer
    CAShapeLayer的使用
    用缓动函数模拟物理动画
  • 原文地址:https://www.cnblogs.com/zdz8207/p/nginx-tomcat-rewrite.html
Copyright © 2011-2022 走看看