虽然我找到了很多使用 WSGI 在 Apache 上部署 Django 的技术支持,但不幸的是,事实上它们都让我感到困惑,我无法让 Django 运行。我希望这真的是一件容易的工作,但作为一个新人,我面临着困难。
我的里面有两个 Django 项目,即 website1 和 website2/home/zia/文档/代码/Django/website1 and ..../网站2分别是dir。包含settings.py文件的文件夹是root/在 - 的里面/网站1 and /网站2 dir.
Apache、mod_wsgi 一切都按要求安装。如何编辑 apache2.conf 和 wsgi.py 文件以保持这两个项目在端口 8080 和 8081 上运行?
过去几天我一直在努力解决这个问题,并尝试了以下所有网站。
link1 https://www.youtube.com/watch?v=hBMVVruB9Vs,link2 http://singlas.in/5-step-tutorial-for-using-django-with-apache-and-mod_wsgi/,link3 https://docs.djangoproject.com/en/1.7/howto/deployment/wsgi/modwsgi/,link4 https://www.digitalocean.com/community/tutorials/how-to-run-django-with-mod_wsgi-and-apache-with-a-virtualenv-python-environment-on-a-debian-vps
UPDATE1:
我从一开始就遵循以下方法以使事情进展顺利,但发现自己遇到了一些新问题。请指导我哪里错了。
- 安装 mod-wsgi 和 apache2:
sudo apt-get install libapache2-mod-wsgi && sudo apt-get update && sudo apt-get install apache2
- 通过更改文件“/etc/apache2/ports.conf”将 apache2 端口编辑为 8083,而不是 80:
Listen 8083
- 将以下行添加到“/etc/hosts”文件中:
160.75.133.175 160.75.133.175
- 在“/etc/apache2/apache2.conf”文件中编辑以下代码:
<Directory />
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
- 在“/etc/apache2/sites-available/”目录中创建一个名为“sql_api.conf”的文件:
<VirtualHost *:8083>
ServerAdmin [email protected] /cdn-cgi/l/email-protection
ServerName 160.75.133.175
ServerAlias http://160.75.133.175
<Directory /home/zia/Documents/Codes/Django/sql_api/ >
Order deny,allow
Allow from all
</Directory>
WSGIScriptAlias / /home/zia/Documents/Codes/Django/sql_api/root/wsgi.py
WSGIDaemonProcess 160.75.133.175 user=www-data group=www-data threads=25 python-path=/home/zia/Documents/Codes/Django/sql_api/root/:/usr
WSGIProcessGroup 160.75.133.175
ErrorLog /home/zia/Documents/Codes/Django/sql_api/root/error.log
</VirtualHost>
- 在“/etc/apache2/sites-available”目录中运行以下命令:
sudo a2enmod wsgi && sudo a2ensite sql_api.conf && sudo service apache2 restart
- Open
http://160.75.133.175:8083/
但出现以下错误:内部服务器错误
服务器遇到内部错误或配置错误,无法完成您的请求。
请联系服务器管理员[电子邮件受保护] /cdn-cgi/l/email-protection通知他们此错误发生的时间以及您在出现此错误之前执行的操作。
有关此错误的更多信息可在服务器错误日志中找到。
Apache/2.4.7 (Ubuntu) 服务器位于 160.75.133.175 端口 8082
NOTE: 当我在制作 Django 项目时/var/www/dir 然后执行相同的方法然后工作得很好!我想因为我正在尝试访问/家/齐亚/....dir,有这个问题。无论如何,这只是一个猜测。我将不胜感激你的帮助。