在我的浏览器www.site2.com上输入后,打开www.site1.com的页面。 我认为我对nginx和gunicorn的配置都很好。
upstream app_server {
server 127.0.0.1:9000 fail_timeout=0;
}
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
index index.html index.htm;
client_max_body_size 4G;
server_name _;
keepalive_timeout 5;
# Your Django project's media files - amend as required
location /media {
alias /home/django/site1/media;
}
# your Django project's static files - amend as required
location /static {
alias /home/django/site1/static_root;
}
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app_server;
}
}
upstream app_server2 {
server 127.0.0.1:9500 fail_timeout=0;
}
server {
listen 80;
listen [::]:80;
root /usr/share/nginx/html;
index index.html index.htm;
client_max_body_size 4G;
server_name www.site2.com site2.com;
keepalive_timeout 5;
# Your Django project's media files - amend as required
location /media {
alias /home/django/test-django/site2/media;
}
# your Django project's static files - amend as required
location /static {
alias /home/django/test-django/site2/static;
}
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app_server2;
}
}
description "Gunicorn daemon for Django project"
start on (local-filesystems and net-device-up IFACE=eth0)
stop on runlevel [!12345]
# If the process quits unexpectedly trigger a respawn
respawn
setuid django
setgid django
chdir /home/django
exec gunicorn \
--name=site1\
--pythonpath=site1 \
--bind=0.0.0.0:9000 \
--config /etc/gunicorn.d/gunicorn.py \
site1.wsgi:application
description "Gunicorn daemon for Django project"
start on (local-filesystems and net-device-up IFACE=eth0)
stop on runlevel [!12345]
# If the process quits unexpectedly trigger a respawn
respawn
setuid django
setgid django
chdir /home/django/test-django/
exec gunicorn \
--name=site2\
--pythonpath=site2 \
--bind=127.0.0.1:9500 \
--config /etc/gunicorn.d/gunicorn.py \
site2.wsgi:application
我没有忘记service nginx restart
和service site2 restart
,也没有nginx -t
我没有任何错误。
答案 0 :(得分:0)
在项目的wsgi.py文件中,您是否为django.conf.ENVIRONMENT_VARIABLE使用相同的变量?通常该行是:os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project_site.settings")
尝试更改那些行:
django.conf.ENVIRONMENT_VARIABLE = "DJANGO_SITEA_SETTINGS_MODULE"
os.environ.setdefault("DJANGO_SITEA_SETTINGS_MODULE", "project_site.settings")
为每个项目更改SITEA以及设置文件所在文件夹名称的project_site.settings。此更改后重新启动服务器。
我不知道这是否是答案,但它可能有所帮助,因为它为我解决了你描述的同样问题。