【问题标题】:how to configure nginx to serve specific django url path with another domain如何配置 nginx 为另一个域提供特定的 django url 路径
【发布时间】:2012-04-28 23:22:20
【问题描述】:

我已经配置了 nginx + uwsgi 来服务 foo.com,但是 foo.com/bar/ 我想像 bar.com 一样服务它

示例: foo.com/bar/test/ = bar.com/test/

我也想让 bar.com 机器人不允许。

有什么建议吗?

【问题讨论】:

    标签: python django nginx


    【解决方案1】:

    假设您将foo.com 配置为:

    location / {
     # your normal stuff
    }
    

    这样的事情应该可以工作:

    location / {
       rewrite  ^/bar/(.*)$  bar.com/$1? break;
    }
    

    对于拦截机器人,请参阅this nginx forum entry

    【讨论】:

      【解决方案2】:
      server {
          listen   80;
          server_name foo.com;
          root   /full/server/path/to/foo/folder;
          index index.html index.php;
          # This redirects anyone that directly types "foo.com/bar/xyz to bar.com/xyz"
          if ($request_uri ~ ^/bar(.*)$) {
              return 301 http://bar.com$1;
              # Alternative for old nginx versions
              # rewrite ^ http://bar.com$1 redirect;
          }
      
          # foo.com location blocks go below
          ...
      }
      
      server {
          listen   80;
          server_name bar.com;
          root /full/server/path/to/foo/bar/folder;
          index index.html index.php;
      
          # bar.com location blocks go below
          ...
      }
      

      【讨论】:

        猜你喜欢
        • 2017-04-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-03-02
        • 2018-06-26
        • 2020-06-28
        • 1970-01-01
        • 2011-10-08
        相关资源
        最近更新 更多