nginx学习资料(转)

    根据项目需求,我们有个主站,主站下面有很多子站。如果访问过子站的用户再次访问主站,直接跳转到子站下去。
   做法:将子站域名存到cookie。然后直接通过cookie跳转。

nginx代码:
server {
        listen       80;
        server_name  domain.com main.domain.com beijing.domain.com shanghai.domain.com;
        set $cookieKey '';
        if ( $http_cookie ~* 'domainKey=([^;]+)(?:;|$)' ) {
          set $cookieKey $1;
        }
        if ( $cookieKey = '' ) {
          set $cookieKey $host;
        }
        if ( $host = 'main.domain.com' ) {
          rewrite ^/ http://$cookieKey permanent;
        }
        root /opt/workspace/main/project/webroot/;


        include server_main.conf;
    }

猜你喜欢

转载自datum.iteye.com/blog/1811174