孤独雪鹰 发表于 2016-12-24 10:23:50

nginx学习资料(转)

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

nginx代码:
server {
listen       80;
server_namedomain.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;
}
页: [1]
查看完整版本: nginx学习资料(转)