![尝试设置 Django 网站,但总是获取 Apache 默认页面](https://linux22.com/image/995869/%E5%B0%9D%E8%AF%95%E8%AE%BE%E7%BD%AE%20Django%20%E7%BD%91%E7%AB%99%EF%BC%8C%E4%BD%86%E6%80%BB%E6%98%AF%E8%8E%B7%E5%8F%96%20Apache%20%E9%BB%98%E8%AE%A4%E9%A1%B5%E9%9D%A2.png)
我正在将我的 Django 网站移至新服务器,但无法在新服务器上运行它。我之前曾运行过它,但一年前我摸索着尝试过,不太记得细节了。
- Ubuntu 16.04 服务器
- Python 3.5.2
- Django 1.10.3
- Apache 2.4.18
- Mod_wsgi 4.5.7
我从源代码构建了 mod_wsgi 并加载了它。当我重新启动 Apache 时,我看到:
Apache/2.4.18 (Ubuntu) mod_wsgi/4.5.7 Python/3.5 configured -- resuming normal operations
所以我认为我做得对。
$ ls /etc/apache2/sites-enabled/
stock.conf
$ cat /etc/apache2/sites-enabled/stock.conf
<VirtualHost tesla:80>
ServerName tesla
ServerAdmin webmaster@localhost
DocumentRoot /nfs/stock_tracker/web
WSGIDaemonProcess stock_tracker
WSGIProcessGroup stock_tracker
WSGIScriptAlias / /nfs/stock_tracker/web/dj/wsgi.py
<Directory /nfs/stock_tracker/web/dj>
Require all granted
<Files wsgi.py>
Require all granted
</Files>
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
$ cat /nfs/stock_tracker/web/dj/wsgi.py
"""
WSGI config for dj project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/1.9/howto/deployment/wsgi/
"""
import os
import time
import traceback
import signal
import sys
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dj.settings")
try:
application = get_wsgi_application()
except Exception:
# Error loading applications
if 'mod_wsgi' in sys.modules:
traceback.print_exc()
os.kill(os.getpid(), signal.SIGINT)
time.sleep(2.5)
我还添加了这个,apache2.conf
以便我的文件可以放在我想要的目录中:
<Directory /nfs/stock_tracker>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
Apache 重新启动且没有错误。一切似乎都正确,但我总是只看到 Apache 默认页面。
知道我错过了什么吗?
请告诉我还有哪些重要信息需要添加。其中一个问题是我没有收到错误,所以这有点神秘。