首页 > 解决方案 > 在 uwsgi Emperor 上托管 2 个不同的 django 网站时出现“无法访问站点”

问题描述

我目前正在尝试使用 Nginx 和 Uwsgi Emperor 在单个 AWS 服务器上托管两个不同的 Django 网站。

这是我的配置文件:

网站1.ini

[uwsgi]

# django-related settings
# the base directory (full path)
project_name    = backend
base_dir        = /home/ubuntu/website1/
virtualenv      = /home/ubuntu/website1/env
#chdir = location where manage.py is present
chdir           = %(base_dir)/backend
# django's wsgi file
module          = %(project_name).wsgi:application
# the virtualenv (full-path)

# process related settings
# master
master          = true

# maximum number of processes
processes       = 10

# the socket (use the full path to be safe)
socket          = /home/ubuntu/server_files/website1socket.sock

# ... with appropriate permissions - may be needed
 chmod-socket   = 666
# clearn environment on exit
vacuum          = true

网站2.ini

[uwsgi]

# django-related settings
# the base directory (full path)
project_name    = website2backend
base_dir        = /home/ubuntu/website2/
virtualenv      = /home/ubuntu/website2/env
#chdir = location where manage.py is present
chdir           = %(base_dir)/djangoRestApi
# django's wsgi file
module          = %(project_name).wsgi:application
# the virtualenv (full-path)
#:home          = /home/ubuntu/website2/env

# process related settings
# master
master          = true

# maximum number of processes
processes       = 5

# the socket (use the full path to be safe)
socket          = /home/ubuntu/server_files/website2socket.sock

# ... with appropriate permissions - may be needed
 chmod-socket   = 666
# clearn environment on exit
vacuum          = true

皇帝.ini

[uwsgi]

emperor = /home/ubuntu/server_files/vassals
uid = ubuntu
gid = ubuntu

website1.conf (/etc/nginx/sites-available/)

upstream django {
    server unix:///home/ubuntu/server_files/website1socket.sock; # for a file socket
}

# configuration of the server
server {
    # the port your site will be served on
    listen      8009;
    # the domain name it will serve for
    server_name <my server IP>; # substitute your machine's IP address or FQDN
    charset     utf-8;

    # max upload size
    client_max_body_size 75M;   # adjust to taste

    location /static {
        alias /home/ubuntu/website1/backend/static; # your Django project's static files - amend as required
    }

    # Finally, send all non-media requests to the Django server.
    location / {
        uwsgi_pass  django;
        include     /home/ubuntu/server_files/uwsgi_params; # the uwsgi_params file you installed
    }
    error_log /home/ubuntu/nginx-log.log;
}

website2.conf(/etc/nginx/sites-available)

upstream django_two {
    server unix:///home/ubuntu/server_files/website2socket.sock; # for a file socket
}

# configuration of the server
server {
    # the port your site will be served on
    listen      8000;
    # the domain name it will serve for
    server_name <my server IP>; # substitute your machine's IP address or FQDN
    charset     utf-8;

    # max upload size
    client_max_body_size 75M;   # adjust to taste

    # Django media
    location /media  {
        alias /path/to/your/mysite/media;  # your Django project's media files - amend as required
    }

    location /static {
        alias /home/ubuntu/website2/djangoRestApi/static; # your Django project's static files - amend as required
    }

    # Finally, send all non-media requests to the Django server.
    location / {
        uwsgi_pass  django_two;
        include     /home/ubuntu/server_files/uwsgi_params; # the uwsgi_params file you installed
    }
    error_log /home/ubuntu/mpac-nginx-log.log;
}

和我的 uwsgi.service:

[Unit]
Description=uWSGI instance to serve both websites (EMPEROR)
After=network.target

[Service]
User=ubuntu
Group=ubuntu

ExecStart=/usr/local/bin/uwsgi --emperor /home/ubuntu/server_files/emperor.iniRestart=alwaysKillSignal=SIGQUIT
Type=notify
NotifyAccess=all

[Install]
WantedBy=multi-user.target

我能够成功启动服务器,但只能访问其中一个站点(端口 8000 的站点),另一个站点只是返回

This site can’t be reached

<IP Address> took too long to respond.
Try:

Checking the connection
Checking the proxy and the firewall
Running Windows Network Diagnostics
ERR_CONNECTION_TIMED_OUT

我在这里做错什么了吗?是否可以在同一服务器 IP 但在不同端口上托管两个站点?请帮忙!

提前致谢!

标签: djangoamazon-web-servicesnginxuwsgi

解决方案


推荐阅读