【问题标题】:Rewrite location to subdomain in nginx在nginx中将位置重写为子域
【发布时间】:2012-01-28 15:04:07
【问题描述】:

如何在 NGINX 中将子域重写为应用程序?

我的配置是

server {
    listen       80;
    server_name domain.com www.domain.com;

    location / {
            include        uwsgi_params;
            uwsgi_pass     127.0.0.1:9001;
            uwsgi_param    UWSGI_PYHOME PATH;
            uwsgi_param    UWSGI_SCRIPT wsgi;
            uwsgi_param    UWSGI_CHDIR PATH;
    }

    location /app1 {
            include        uwsgi_params;
            uwsgi_pass     127.0.0.1:9001;
            uwsgi_param    UWSGI_PYHOME PATH2;
            uwsgi_param    UWSGI_SCRIPT wsgi2;
            uwsgi_param    UWSGI_CHDIR PATH2;
            uwsgi_modifier1 30;
    }
}

我想在访问 app1.domain.com 时被重写为 domain.com/app1。我该怎么做?

提前致谢。

【问题讨论】:

    标签: configuration nginx subdomain rewrite uwsgi


    【解决方案1】:

    您可以将子域添加到服务器名称,在这种情况下,它将作为域工作,但不会重定向用户并且地址栏将显示子域:

    server {
        listen       80;
        server_name domain.com www.domain.com app1.domain.com;
    
        location / {
                include        uwsgi_params;
                ...
        }
    }
    

    或者,您可以为重定向到域的子域创建特定服务器:

    server {
        listen       80;
        server_name app1.domain.com;
        rewrite ^ http://domain.com$request_uri? permanent;
    }
    
    server {
        listen       80;
        server_name domain.com www.domain.com;
    
        location / {
            include        uwsgi_params;
            ...
        }
    }
    

    【讨论】:

      【解决方案2】:

      我认为您不需要 - 您可以添加另一个服务器部分,例如:

      server {
        server_name app1.domain.com;
        location / {
          <uwsgi as before>
        }
      }
      

      而不是 location /app1 后跟重定向。希望对您有所帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-03-05
        • 1970-01-01
        • 2017-11-13
        • 1970-01-01
        • 1970-01-01
        • 2011-01-30
        • 1970-01-01
        相关资源
        最近更新 更多