1

Typing in the domain name in a brower shows the "index of /" page, instead of the content of my website. I'm using django, mod-wsgi and apache on ec2.

My apache conf file looks like this:

<VirtualHost 52.79.**.**:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/qna
Alias /m/ /var/www/qna/static/
Alias /upfiles/ /var/www/qna/askbot/upfiles/
<DirectoryMatch “/var/www/qna/askbot/skins/([^/]+)/media”>
Require all granted
</DirectoryMatch>
<Directory “/var/www/qna/askbot/upfiles”>
Require all granted
</Directory>
WSGIDaemonProcess qna
WSGIProcessGroup qna
WSGIScriptAlias / /var/www/qna/django.wsgi
<LocationMatch “(?!/m)/admin(?!/media)”>
RewriteEngine on
RewriteRule /admin(.*)$ https://mywebsite.com/admin$1 [L,R=301]
</LocationMatch>
CustomLog /var/log/apache2/t_access_log common
ErrorLog /var/log/apache2/qna_error_log
LogLevel debug
</VirtualHost>
<VirtualHost 52.79.**.**:443>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/qna
<LocationMatch "^(?!/admin)">
RewriteEngine on
RewriteRule django.wsgi(.*)$ http://mywebsite.com$1 [L,R=301]
</LocationMatch>
SSLEngine on
SSLCertificateFile /etc/ssl/private/qna.crt
SSLCertificateKeyFile /etc/ssl/private/qna.key
Alias /admin/media/ /usr/local/lib/python2.7/dist-packages/django/contrib/admin/static/media/
Alias /m/ /var/www/qna/static/
WSGIScriptAlias / /var/www/qna/django.wsgi
CustomLog /var/log/apache2/qna_access_log common
ErrorLog /var/log/apache2/qna_error_log
</VirtualHost>

I am a newbie and I assume there is something fundamentally wrong with the apache setting. I've spent the last four days on this, tried everything to resolve this but solved nothing.

I assume that there is something wrong with WSGI setting because apache does not understand django. The settings.py file is in /var/www/qna.

Django 1.8.8 and Python 2.7.6, on Amazon ec2 Ubuntu. Thank you in advance. Please help.

I tried changing to and added ServerName mysite.com and also ServerAlias but in this case I get 500 Internal Server Error.

VirtualHost configuration:
*:80                   mysite.com (/etc/apache2/sites-enabled/qna.conf:1)
*:443                  mysite.com (/etc/apache2/sites-enabled/qna.conf:31)
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex rewrite-map: using_defaults
Mutex ssl-stapling: using_defaults
Mutex ssl-cache: using_defaults
Mutex default: dir="/var/lock/apache2" mechanism=fcntl 
Mutex watchdog-callback: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33 not_used
Group: name="www-data" id=33 not_used

But when I run python maange.py runserver 0.0.0.0:80 it works fine with no problem. I can access the website typing the domain name.

2
  • @Paul I don't have an index.html.
    – SJ H
    Feb 4, 2016 at 4:05
  • Ignore my comment about DirectoryIndex, I can see in Jake's reformatted config that there is an alias for /.
    – Paul
    Feb 4, 2016 at 5:06

2 Answers 2

1

Here are your configs; reformatted my me for readability:

<VirtualHost 52.79.**.**:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/qna

    Alias /m/ /var/www/qna/static/
    Alias /upfiles/ /var/www/qna/askbot/upfiles/

    <DirectoryMatch “/var/www/qna/askbot/skins/([^/]+)/media”>
        Require all granted
    </DirectoryMatch>

    <Directory “/var/www/qna/askbot/upfiles”>
        Require all granted
    </Directory>

    WSGIDaemonProcess qna
    WSGIProcessGroup qna
    WSGIScriptAlias / /var/www/qna/django.wsgi

    <LocationMatch “(?!/m)/admin(?!/media)”>
        RewriteEngine on
        RewriteRule /admin(.*)$ https://mywebsite.com/admin$1 [L,R=301]
    </LocationMatch>

    CustomLog /var/log/apache2/t_access_log common
    ErrorLog /var/log/apache2/qna_error_log

    LogLevel debug

</VirtualHost>

<VirtualHost 52.79.**.**:443>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/qna

    <LocationMatch "^(?!/admin)">
        RewriteEngine on
        RewriteRule django.wsgi(.*)$ http://mywebsite.com$1 [L,R=301]
    </LocationMatch>

    SSLEngine on
    SSLCertificateFile /etc/ssl/private/qna.crt
    SSLCertificateKeyFile /etc/ssl/private/qna.key

    Alias /admin/media/ /usr/local/lib/python2.7/dist-packages/django/contrib/admin/static/media/
    Alias /m/ /var/www/qna/static/

    WSGIScriptAlias / /var/www/qna/django.wsgi

    CustomLog /var/log/apache2/qna_access_log common
    ErrorLog /var/log/apache2/qna_error_log

</VirtualHost>

I am assuming if you have a virtual host setup in place, if you attempt to access the website via the IP address of 52.79.**.**:80 everything is fine, but if you are accessing it via a hostname/domain name like example.com then it is choking, correct? If that is the case what you need to do is set the virtual host lines like this:

<VirtualHost *:80>

And this for HTTPS:

<VirtualHost *:443>

Then within those config blocks you would set a ServerName value like this; of course this is not a full config but just a example of what you should change:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/qna

    ServerName www.example.com
    ServerAlias www example.* www.example.*

Doing something like this would allow the virtual host config to work correctly with www.example.com being the actual server name connected to that config and then ServerAlias allows the config to capture other variants of www.example.com such as example.com or www.example.net.

0

The found the solution thanks to Giacomo1968's answer. Thank you so much, you saved my day!

It was rather simple, it was the permission issue.

As suggested, I checked /var/log/apache2/qna_error_log, and it said IOError: [Errno 13] Permission denied: '/var/www/qna/log/askbot.log'

So I changed permission of /var/www/qna/log by using sudo chmod -R 777 /var/www/ (I don't believe setting 777 is a good solution but I just did).

Now I got the following error:

ExtractionError: Can't extract file(s) to egg cache

The following error occurred while trying to extract file(s) to the Python egg
cache:

  [Errno 13] Permission denied: '/var/www/.python-eggs'

The Python egg cache directory is currently set to:

  /var/www/.python-eggs`

As suggested in here, I made a new directory /usr/local/pylons and edited django.wsgi in /var/www/qna as below:

import os
os.environ['PYTHON_EGG_CACHE'] = '/usr/local/pylons/python-eggs'

And it's fixed! Now I see my website, not the "index of" page.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .