django - 在 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 但在不同端口上托管两个站点?请帮忙!
提前致谢!
解决方案
推荐阅读
- node.js - Google Cloud Speech Recognition grpc 版本与 VSCode Electron 版本不兼容
- sql-server - 如何在 SQL 比较中比较脚本文件夹从 TFS 到数据库时检测 TFS 数据库 CLR 程序集文件
- python - Python3 中是否有机会创建数组数组的矩阵?
- node.js - 使用 NodeJS HTTP 服务器对 HTTPS 端点的 POST 请求是否易受攻击?
- css - 如何使用 Sass 和 BEM 编写修饰符
- firebase - 从数据库读取时权限被拒绝
- python - 如何在 Flask Python 中修复“找不到此页面”?
- html - 我正在尝试让我的 CSS 再次在本地工作
- python-3.x - readline() 导致 pyserial python 2 和 3 的兼容性
- amazon-web-services - 将 HBase 中的数据作为 RDD 直接查询到 Spark 中,还是通过 Phoenix 作为 Dataframe 查询?