1

我正在尝试使用 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/wwwurl,如下图所示。

在此处输入图像描述

并且所有其他应用程序都可以访问,IP/html/app_name而它们应该可以从IP/app_name

我无法在配置文件中进行正确的配置。

此外,我无法在访问时看到“欢迎使用 django”页面IP/django。它宁愿给出一个“页面未找到(404)

在访问IP/django.
在此处输入图像描述

在访问时获取此页面IP/django
虽然,IP/django/admin工作正常。
在此处输入图像描述

4

2 回答 2

0

/django您已经特别要求 Apache通过将该路径作为 WSGIScriptAlias来为您的 Django 应用程序提供服务。如果你想要它/,这是正常的做法,你应该/在那里使用。

于 2015-12-24T15:18:21.567 回答
0

在阅读了有关配置文档的更多信息后,我终于找到了解决方案。

<VirtualHost *:80>

    Alias /static /home/ubuntu/app/static
    Alias /media /home/ubuntu/app/media

    DocumentRoot /var/www/html

    <Directory /home/ubuntu/app/static>
        Require all granted
    </Directory>

    WSGIDaemonProcess app python-path=/home/ubuntu/app:/usr/local/lib/python2.7/site-packages
    WSGIProcessGroup app
    WSGIScriptAlias /django /home/ubuntu/app/app/wsgi.py process-group=app

    <Directory /home/ubuntu/app/app>
        <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 ocdemo.example.co.in
DocumentRoot /var/www/html/ocdemo
</VirtualHost>

<VirtualHost *:80>
ServerName echosuat.example.co.in
DocumentRoot /var/www/html/echosuat
</VirtualHost>

<VirtualHost *:80>
ServerName task.example.co.in
DocumentRoot /var/www/html/tasks
</VirtualHost>

我需要更改的只是在 django 应用程序的配置中添加 DocumentRoot。

于 2015-12-27T09:55:57.770 回答