在一个 VPS 服务器中托管 2 个 django 项目

Hosting 2 django project inside one VPS server

我正在尝试 运行 2 个不同域中的单个 VPS 服务器中的 2 个 django 项目。我正在使用 gunicorn 作为我的项目服务器。 我在站点可用和启用文件夹中创建了 2 个虚拟环境、2 个主管和 2 个单独的文件。 我的项目 运行ning 很好,但问题是曾经只有一个项目在两个域中 运行ning。尽管在我的 nginx 站点中,可用文件被赋予了不同的域,因为 server_name 仍然有一个 django 项目 运行ning 两个域 有谁能帮忙吗

/etc/nginx/sites-avaiable/VaidText

upstream sample_project_server {
  # fail_timeout=0 means we always retry an upstream even if it failed
  # to return a good HTTP response (in case the Unicorn master nukes a
  # single worker for timing out).
  server unix:/home/example/test.example.com/TestEnv/run/gunicorn.sock fail_timeout=0;
}
server {
listen   80;
server_name test.example.com;

client_max_body_size 4G;
access_log /home/example/test.example.com/logs/nginx-access.log;
error_log /home/example/test.example.com/logs/nginx-error.log;

location /static/ {
    alias   /home/ubuntu/static/;
}

location /media/ {
    alias   /home/ubuntu/media/;
}

location / {

    # an HTTP header important enough to have its own Wikipedia entry:
    #   http://en.wikipedia.org/wiki/X-Forwarded-For
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;


    # enable this if and only if you use HTTPS, this helps Rack
    # set the proper protocol for doing redirects:
    # proxy_set_header X-Forwarded-Proto https;

    # pass the Host: header from the client right along so redirects
    # can be set properly within the Rack application
    proxy_set_header Host $http_host;

    # we don't want nginx trying to do something clever with
    # redirects, we set the Host: header above already.
    proxy_redirect off;

    # set "proxy_buffering off" *only* for Rainbows! when doing
    # Comet/long-poll stuff.  It's also safe to set if you're
    # using only serving fast clients with Unicorn + nginx.
    # Otherwise you _want_ nginx to buffer responses to slow
    # clients, really.
    # proxy_buffering off;

    # Try to serve static files from nginx, no point in making an
    # *application* server like Unicorn/Rainbows! serve static files.
    if (!-f $request_filename) {
        proxy_pass http://sample_project_server;
        break;
    }
}

# Error pages
error_page 500 502 503 504 /500.html;
location = /500.html {
    root /home/ubuntu/static/;
}

}

/etc/nginx/sites-avaiable/SheikhText

  upstream sample_project_server {
  # fail_timeout=0 means we always retry an upstream even if it failed
  # to return a good HTTP response (in case the Unicorn master nukes a
  # single worker for timing out).
  server 

unix:/home/example/sheikhnoman.example.com/SheikhEnv/run/gunicorn.sock fail_timeout=0;
}

server {

listen   80;
server_name sheikhnoman.example.com;

client_max_body_size 4G;
access_log /home/example/sheikhnoman.example.com/logs/nginx-access.log;
error_log /home/example/sheikhnoman.example.com/logs/nginx-error.log;

location /static/ {
    alias   /home/ubuntu/sheikhnoman/static/;
}

location /media/ {
    alias   /home/ubuntu/sheikhnoman/media/;
}

location / {

    # an HTTP header important enough to have its own Wikipedia entry:
    #   http://en.wikipedia.org/wiki/X-Forwarded-For
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;


    # enable this if and only if you use HTTPS, this helps Rack
    # set the proper protocol for doing redirects:
    # proxy_set_header X-Forwarded-Proto https;

    # pass the Host: header from the client right along so redirects
    # can be set properly within the Rack application
    proxy_set_header Host $http_host;

    # we don't want nginx trying to do something clever with
    # redirects, we set the Host: header above already.
    proxy_redirect off;

    # set "proxy_buffering off" *only* for Rainbows! when doing
    # Comet/long-poll stuff.  It's also safe to set if you're
    # using only serving fast clients with Unicorn + nginx.
    # Otherwise you _want_ nginx to buffer responses to slow
    # clients, really.
    # proxy_buffering off;

    # Try to serve static files from nginx, no point in making an
    # *application* server like Unicorn/Rainbows! serve static files.
    if (!-f $request_filename) {
        proxy_pass http://sample_project_server;
        break;
    }
}

# Error pages
error_page 500 502 503 504 /500.html;
location = /500.html {
    root /home/ubuntu/sheikhnoman/static/;
}
}

您的两个 nginx 配置文件包含相同的 "sample_project_server" upstream name。尝试为每个文件设置不同的 upsteam 名称。