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 {
        }
    
    }
  • 相关阅读:
    简单工厂
    Asp.Net Catch的应用
    ADO和ADO.NET的区别
    PLSql语句学习(三)
    三层结构的B/S系统(收藏)
    MVC 模式
    利用.net反射动态调用指定程序集的中的方法
    .NET反射的简单示例
    ToString格式化
    HTML:关于位置的几个概念
  • 原文地址:https://www.cnblogs.com/zdz8207/p/nginx-tomcat-rewrite.html
Copyright © 2011-2022 走看看