zoukankan      html  css  js  c++  java
  • nginx rewrite 实现二级域名跳转

    当访问http://cbs.test.com跳转到http://www.test.com/test/cbs/
    方法一: (这种方法浏览器地址会变www.test.com/test/cbs)
    server { 
          listen 80; 
          server_name www.test.com
          location / { 
              root /data/test; 
              index index.html; 
              }

           }


    server { 
          listen 80; 
          server_name *.test.com; 
          if ( $http_host ~* "^(.*).test.com$") { 
               set $domain $1; 
               rewrite ^(.*) http://www.test.com/test/$domain/ break; 
              }  

          }

    方法二: (这样配置浏览器的地址就会显示成http://cbs.test.com)

    server { 
                    listen 80; 
                    server_name *.test.com; 
                    root /usr/local/www; 
                    location ~ ^/(test|images|styles)/ 这是里可以加多个目录,如果不加目录,会无法访问到cbs.test.com/目录下的文件,如图片目录/images
                    { 
                          proxy_redirect        off; 
                          proxy_set_header    Host   www.test.com
                          proxy_pass      http://192.168.1.3:80
                    }

                    location / { 
                                    set $domain default; 
                                    if ( $http_host ~* "^(.*).test.com$") { 
                                                    set $domain $1; 
                                    } 
                                    rewrite ^/(.*)    /test/$domain/$1 last; 
                    } 
                                                } 
                    access_log off; 
    }

    详细过程

    如:bs.myweb.com   访问/data0/htdocs/bs

    vi /usr/local/webserver/nginx/conf/nginx.conf

      server
      {
        listen       80;
        server_name  bs.myweb.com;
        index index.html index.htm index.php;
        root  /data0/htdocs/bs;

        location ~ .*.(php|php5)?$
        {
          #fastcgi_pass  unix:/tmp/php-cgi.sock;
          fastcgi_pass  127.0.0.1:9000;
          fastcgi_index index.php;
          include fcgi.conf;
        }
      }


    /usr/local/webserver/nginx/sbin/nginx -t

    /usr/local/webserver/nginx/sbin/nginx -s reload

  • 相关阅读:
    Dialog 不能全屏,左右有间距解决方案
    mac apktool配置
    HTML5网站如何做到完全不需要jQuery
    js中控制小数点的显示位数的技术整理
    ASP.NET后台获取cookie中文乱码解决办法
    javascript删除元素节点
    js获取不到动态添加的标签的值的解决方法
    JS常用方法函数整理
    JS获取当前页面的URL信息
    轻轻松松 用U盘安装WIN7
  • 原文地址:https://www.cnblogs.com/goldenstones/p/5596416.html
Copyright © 2011-2022 走看看