简体   繁体   中英

Error on deploying Django app using WSGI on Apache2 server

I am trying to setup the Django app on Apache2 server with Ubuntu. I used the following tutorials to do the essentials.
https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-apache-and-mod_wsgi-on-ubuntu-14-04

I also used the following solution but it did not work for me.
Django (wsgi) and Wordpress coexisting in Apache virtualhost

Other References:
https://docs.djangoproject.com/en/1.9/howto/deployment/wsgi/modwsgi/

My config file for apache2 is as follows.

<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>

I am able to access the django app using IP/django but accessing the root of the server redirects to the the /var/www url as shown in the below image.

在此处输入图片说明

And all the other apps are accessible from IP/html/app_name while they should be accessible from IP/app_name

I am unable to make the correct configuration in the configuration file.

Also, I am unable to see the "welcome to django" page on accessing IP/django . It rather gives a " Page not found (404) "

Not getting the default django page, on accessing IP/django .
在此处输入图片说明

Getting this page on accessing IP/django
Though, IP/django/admin works fine.
在此处输入图片说明

You've specifically asked Apache to serve your Django app at /django by putting that path as the WSGIScriptAlias. If you want it at / , which is the normal thing to do, you should use / there.

After reading more about the configuration documentations, i finally arrived at the solution.

<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>

All i needed to change was to add the DocumentRoot in the config of the django app.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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