相关疑难解决方法(0)

nginx子域和域重写w代理传递

我需要这两种类型的重写:

subdomain.domain.com => domain.com/website/subdomain

otherdomain.com => domain.com/userdomain/otherdomain.com

我的问题是我希望用户看到subdomain.domain.com,而otherdomain.com不是重定向的版本.我目前在nginx中的重写工作,但用户的URL显示重写,我希望这对用户透明,任何想法?:

upstream domain_server { server localhost:8000 fail_timeout=0; }     

server {
        listen  80;
        root  /var/www/domain.com;

        server_name domain.com ~^(?<subdomain>.*)\.domain\.com$ ~^(?<otherdomain>.*)$;
        if ( $subdomain ) {
                rewrite ^ http://domain.com/website/$subdomain break;
        }
        if ( $otherdomain ) {
                rewrite ^ http://domain.com/userdomain/$otherdomain break;
        }

        location / {
                proxy_redirect off;
                proxy_buffering off;
                proxy_set_header Host $http_host;
                proxy_set_header X-forwarded-for $proxy_add_x_forwarded_for;
                if (!-f $request_filename) {
                        proxy_pass http://domain_server;
                        break;
                }
        }

}
Run Code Online (Sandbox Code Playgroud)

django proxy rewrite nginx

11
推荐指数
1
解决办法
2万
查看次数

标签 统计

django ×1

nginx ×1

proxy ×1

rewrite ×1