【问题标题】:Run two different django-cms applications with different domains on the same ip on nginx在 nginx 上的同一 ip 上运行两个具有不同域的不同 django-cms 应用程序
【发布时间】:2014-07-21 02:49:24
【问题描述】:

我想要两个在一台服务器上托管两个具有不同域的不同 django-cms 应用程序,该服务器具有运行 nginx 的相同 IP 地址。

我已经找到了这个相关的问题,但是我无法将解决方案翻译到我的 python 应用程序:Nginx Different Domains on Same IP

我已经在端口 7000 上使用 uwsgi 运行第一个 django-cms 应用程序,并通过 nginx 提供服务。

现在我想添加第二个 django-cms 应用程序,也使用端口 9000 上的 uwsgi 用于与我当前的 nginx 配置不同的域。

我尝试将第二个 uwsgi 应用程序添加到 nginx 的上游 app_servers 部分,但这不起作用并导致错误。

这是我当前的 nginx 配置:

worker_processes 1;

events {

    worker_connections 1024;

}

http {

    types_hash_max_size 2048;   
    include /etc/nginx/mime.types;
    sendfile on;

    gzip              on;
    gzip_http_version 1.0;
    gzip_proxied      any;
    gzip_min_length   500;
    gzip_disable      "MSIE [1-6]\.";
    gzip_types        text/plain text/xml text/css
                      text/comma-separated-values
                      text/javascript
                      application/x-javascript
                      application/atom+xml;

    # Configuration containing list of application servers
    upstream app_servers {

        server 127.0.0.1:7000;
        #server 127.0.0.1:9000;
        # ..
        # .

    }

    # Configuration for Nginx
    server {

        # Running port
        listen 80;
    server_name www.myfirstdomain.at;

        # Settings to serve static files 
        location ^~ /static/  {

            # Example:
            # root /full/path/to/application/static/file/dir;
            alias /webapps/first-django-cms-app/static/;

        }

        # Serve a static file (ex. favico)
        # outside /static directory
        location = /favico.ico  {

            root /app/favico.ico;

        }

        # Proxy connections to the application servers
        # app_servers
        location / {

            include       /etc/nginx/mime.types;        
            proxy_pass         http://app_servers;
            proxy_redirect     off;
            proxy_set_header   Host $host;
            proxy_set_header   X-Real-IP $remote_addr;
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header   X-Forwarded-Host $server_name;

        }
    }
}

如何更改我的 nginx 配置以实现这一点?

【问题讨论】:

    标签: python django nginx dns django-cms


    【解决方案1】:

    您需要两个具有不同服务器名称的 server 部分和两个具有不同名称的 upstream 部分,例如app_server_1app_server_2

    【讨论】:

    • 这正是我想要的,谢谢。为了完成,我还必须在我的配置的 http 部分添加这一行: server_names_hash_bucket_size 64;并且上游app_servername必须在服务器位置代理pass属性中设置:app_server1;
    • 是这个stackoverflow.com/questions/63148739/…的任何解决方案
    猜你喜欢
    • 2015-08-21
    • 2012-07-31
    • 2020-10-26
    • 1970-01-01
    • 2013-10-26
    • 2018-12-28
    • 2020-04-02
    • 2019-01-20
    • 1970-01-01
    相关资源
    最近更新 更多