两个Django项目部署到Apache2同一个地址不同端口异常导致其中一个网站崩溃问题解决
作者:互联网
先上ports.conf及相关文件:
ports.conf
# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default.conf
NameVirtualHost *:80
Listen 80
NameVirtualHost *:81
Listen 81
<IfModule ssl_module>
Listen 443
</IfModule>
<IfModule mod_gnutls.c>
Listen 443
</IfModule>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
Django项目一sites-available/conf文件:
<VirtualHost *:80>
ServerName xxx
ServerAdmin xxx
WSGIScriptAlias / /var/www/xxx/xxx/wsgi.py
Alias /media/ /var/www/xxx/media/
Alias /static/ /var/www/xxx/static/
<Directory /var/www/xxx/media>
Require all granted
</Directory>
<Directory /var/www/xxx>
Require all granted
</Directory>
<Directory /var/www/xxx/static>
Require all granted
</Directory>
<Directory /var/www/xxx/xxx>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Django项目二sites-available/conf文件:
<VirtualHost *:81>
ServerName xxx
ServerAdmin xxx
WSGIScriptAlias / /var/www/QXTechnology/QXTechnology/wsgi.py
Alias /media/ /var/www/QXTechnology/media/
Alias /static/ /var/www/QXTechnology/static/
<Directory /var/www/QXTechnology/media>
Require all granted
</Directory>
<Directory /var/www/QXTechnology>
Require all granted
</Directory>
<Directory /var/www/QXTechnology/static>
Require all granted
</Directory>
<Directory /var/www/QXTechnology/QXTechnology>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
出现的现象是:打开网站一,则再打开网站二出现崩溃;先打开网站二,则反之。
最后发现问题出在wsgi.py文件。
其中一个wsgi.py文件我只设置了os.environ.setdefault(‘DJANGO_SETTINGS_MODULE’, ‘xxx.settings’),而漏了os.environ[‘DJANGO_SETTINGS_MODULE’] = ‘xxx.settings’。
最后两个文件都设置了即解决了问题。
标签:www,granted,xxx,端口,Django,conf,var,Apache2,Require 来源: https://blog.csdn.net/qq_21649903/article/details/120899224