繁体   English   中英

如何使用Apache2部署Django应用VPS?

[英]How to deploy Django app VPS using Apache2?

我遵循了本教程,这是各种教程推荐的部署Django的方法。

https://www.digitalocean.com/community/tutorials/how-to-serv-django-applications-with-apache-and-mod_wsgi-on-ubuntu-14-04

这是我的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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM