[英]How to deploy Django app VPS using Apache2?
我遵循了本教程,這是各種教程推薦的部署Django的方法。
這是我的000-default.conf文件的內容。
更新的“ .conf”文件
<VirtualHost *:80>
Alias /static /home/myproject/static
<Directory /home/myproject/static>
Require all granted
</Directory>
<Directory /home/myproject/myproject>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess myproject python-home=/home/myproject/myprojectenv python-path=/home/myproject/myprojectenv/lib/python2.7/site-packages
WSGIProcessGroup myproject
WSGIScriptAlias / /home/myproject/myproject/wsgi.py
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
這是我第一次在配備“ ubuntu-16.04-64bit”的VPS上部署Django Web應用程序的經驗。
在啟用virtualenv並使用Django默認服務器的情況下,我能夠獲取“ myproject” Django應用程序:
./manage.py runserver 0.0.0.0:8000
並能夠通過my_ip(由“ xx.xxx.xxx.xx”和端口8000表示)成功打開myproject應用。
http://xx.xxx.xxx.xx:8000
同時,在停用virtualenv並按照給定教程所述配置apache2服務器后,該服務器無法正常工作。
如教程所述,在服務器上成功安裝並配置Django應用后,它僅應與您的IP兼容,如下所示:
http://xx.xxx.xxx.xx
在我的情況下,這不起作用,而是在瀏覽器上顯示“ Waiting for xx.xxx.xxx.xx ....”表示無窮大。
This site can’t be reached
xx.xxx.xxx.63 refused to connect.
Search Google for 188 167 8000
ERR_CONNECTION_REFUSED
而且它不會為apache2生成任何日志
ErrorLog /home/error.log
CustomLog /home/access.log combined
從早上開始我一直在努力,但是沒有成功,請幫助...
更新
Apache2錯誤日志:
[Thu Nov 09 03:38:23.800566 2017] [core:warn] [pid 8823:tid 140238720010112] AH00045: child process 8827 still did not exit, sending a SIGTERM
[Thu Nov 09 03:38:25.802552 2017] [core:warn] [pid 8823:tid 140238720010112] AH00045: child process 8827 still did not exit, sending a SIGTERM
[Thu Nov 09 03:38:27.804431 2017] [core:warn] [pid 8823:tid 140238720010112] AH00045: child process 8827 still did not exit, sending a SIGTERM
[Thu Nov 09 03:38:29.805890 2017] [core:error] [pid 8823:tid 140238720010112] AH00046: child process 8827 still did not exit, sending a SIGKILL
[Thu Nov 09 03:38:30.806571 2017] [mpm_event:notice] [pid 8823:tid 140238720010112] AH00491: caught SIGTERM, shutting down
[Thu Nov 09 03:38:31.551724 2017] [mpm_event:notice] [pid 8960:tid 140082895366016] AH00489: Apache/2.4.7 (Ubuntu) mod_wsgi/3.4 Python/2.7.6 configured -- resuming normal operations
[Thu Nov 09 03:38:31.551837 2017] [core:notice] [pid 8960:tid 140082895366016] AH00094: Command line: '/usr/sbin/apache2'
ImportError: No module named site
ImportError: No module named site
ImportError: No module named site
ImportError: No module named site
ImportError: No module named site
這是我的“ wsgi.py”內容
"""
WSGI config for myproject 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.10/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings")
application = get_wsgi_application()
有關如何在虛擬環境中正確設置mod_wsgi的信息,請參見:
ImportError: No module named site
問題ImportError: No module named site
看起來像您不能為要使用的Python版本編譯mod_wsgi。 看到:
因為這是該問題的變體。
通過以下所有安裝檢查:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.