【问题标题】:How to setup nginx for multiple website under one domain?如何为一个域下的多个网站设置 nginx?
【发布时间】:2019-03-30 07:20:54
【问题描述】:

我使用 django 创建了两个网站(带有数据库),我们称它们为 web1 (database=web1_db) 和 web2 (database=web2_db)。我想以这种方式在一个域下运行它们(例如main.html,每个网站都有url.py来引导页面):

www.mywebsite.com/web1/main.html

www.mywebsite.com/web2/main.html

我正在使用 nginx 和 uwsgi 为网站提供服务,我可以让 web1 和 web2 分别工作。为了如上所述为这两个网站提供服务,我在帝王模式下设置了 uwsgi(我认为是成功的),但我不知道应该如何配置 nginx 以使其工作。有人可以给我一些建议吗?

我的单个网站的 nginx 配置如下:

upstream mywebsite {
server unix:///tmp/mywebsite.sock;
}

server {
listen 80;
server_name www.mywebsite.com;
proxy_http_version 1.1;
ssl_protocols TLSv1.2;

location /media{
    alias /pathtomedia;
}

location /static{
    alias /pathtostatic;
}

location / {
    include /etc/nginx/uwsgi_params;
    include /etc/nginx/mime.types;
    uwsgi_pass mywebsite;
}
}

【问题讨论】:

    标签: django nginx uwsgi


    【解决方案1】:

    您必须使用两个(web1 和 web2)上游并且对于每个位置块 location /web1 { something; }uwsgi_pass 到您的上游。

    您可能还需要重写 url,以便您的 url 的实际“/web*”部分不会传递到上游。基本上,所以上游认为请求实际上是“/whatever”而不是“/web1/whatever”。

    本尼格说,这完全取决于您的设置以及任何人在任何 url 重写方面提供帮助(如果甚至需要),需要更多信息。

    您可能想查看此答案Defining correctly Nginx server block for two django apps and no server_name,这可能会对您有所帮助。

    【讨论】:

      猜你喜欢
      • 2020-07-14
      • 2011-11-26
      • 2012-08-25
      • 1970-01-01
      • 1970-01-01
      • 2021-09-25
      • 1970-01-01
      • 1970-01-01
      • 2017-03-31
      相关资源
      最近更新 更多