1

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.

enter image description here

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.
enter image description here

Getting this page on accessing IP/django
Though, IP/django/admin works fine.
enter image description here

2
  • Do you have any Apache log files you can share? Commented Dec 24, 2015 at 13:43
  • I would be adding them by tomorrow. I looked at the logs and found them of not much use. Commented Dec 24, 2015 at 18:35

2 Answers 2

0

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes. It is exactly i want to do. The problem is the php apps are not accessible properly. I want them to be accessible using /app_name but now they are accessible using /html/app_name.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.