我正在尝试使用 Ubuntu 在 Apache2 服务器上设置 Django 应用程序。我使用以下教程来完成基本操作。
https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-apache-and-mod_wsgi-on-ubuntu-14-04
我也使用了以下解决方案,但它对我不起作用。
Django (wsgi) 和 Wordpress 在 Apache 虚拟主机中共存
其他参考:
https ://docs.djangoproject.com/en/1.9/howto/deployment/wsgi/modwsgi/
我的 apache2 配置文件如下。
<VirtualHost *:80>
Alias /static /home/ubuntu/test_pfi_app/static
#Alias /media /home/ubuntu/test_pfi_app/media
#DocumentRoot /var/www/html
<Directory /home/ubuntu/test_pfi_app/static>
Require all granted
</Directory>
WSGIDaemonProcess myproject python-path=/home/ubuntu/test_pfi_app:/usr/local/lib/python2.7/site-packages
WSGIProcessGroup myproject
WSGIScriptAlias /django /home/ubuntu/test_pfi_app/myproject/wsgi.py process-group=myproject
#WSGIScriptAliasMatch /django /home/ubuntu/test_pfi_app/myproject/wsgi.py
<Directory /home/ubuntu/test_pfi_app/myproject>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerName app1.example.co.in
DocumentRoot /var/www/html/ocdemo
</VirtualHost>
<VirtualHost *:80>
ServerName app2.example.co.in
DocumentRoot /var/www/html/echosuat
</VirtualHost>
<VirtualHost *:80>
ServerName task.example.co.in
DocumentRoot /var/www/html/tasks
</VirtualHost>
我可以使用访问 django 应用程序,IP/django
但访问服务器的根目录会重定向到/var/www
url,如下图所示。
并且所有其他应用程序都可以访问,IP/html/app_name
而它们应该可以从IP/app_name
我无法在配置文件中进行正确的配置。
此外,我无法在访问时看到“欢迎使用 django”页面IP/django
。它宁愿给出一个“页面未找到(404) ”