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.

6
  • You say you are using the “domain name” in a browser, but your configs are all IP based like this: 52.79.**.**:80. This could be a case where ServerName should be set. – Giacomo1968 Feb 4 '16 at 4:03
  • @Paul I don't have an index.html. – SJ H Feb 4 '16 at 4:05
  • @JakeGould Thank you. I tried setting the ServerName to my domain name, but still doesn't work. – SJ H Feb 4 '16 at 4:06
  • @SJH Please look at my full answer to understand how I believe a virtual host config should be set. You should set a wildcard value for the virtual host like this: <VirtualHost *:80> and then set ServerName in the config as well. Then restart Apache and check it out. Also, check the output of apachectl -S to ensure the configs are properly recognized by Apache. Might be helpful if the output of apachectl -S could be added to your answer. – Giacomo1968 Feb 4 '16 at 4:13
  • Ignore my comment about DirectoryIndex, I can see in Jake's reformatted config that there is an alias for /. – Paul Feb 4 '16 at 5:06
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

You need to add a DirectoryIndex to your node.

See https://httpd.apache.org/docs/2.4/mod/mod_dir.html#directoryindex

ninja edit: I didnt see the numerous comments already detailing this

1
  • There’s no need to specify a directory index in a virtual host config; that’s already handled in the main Apache config. – Giacomo1968 Feb 4 '16 at 5:32
0

The found the solution thanks to JakeGould. 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.

2
  • In general, this site is not a message board or chatroom. If my answer—or anyone’s—helped you, you need to uproot it and if it is the answer that solved the provided the solution to your issue you need to check it off as such. It’s true that the 2nd half of your answer provides more insight as to what you did to ultimately solve this question, so this answer should stand but anyone else who helped you—not just me—should always be rewarded for helping you clear things up with up votes and checking answers off. – Giacomo1968 Feb 4 '16 at 18:36
  • @JakeGould Thank you for your comments. I'm new to this site so I'm not familiar with the rules. I already tried to upvote your answer and others (which I do appreciate) but my lack of reputation points, i couldn't upvote your answer. Anyways, thank you again so much again for your kind help and it was absolutely helpful. – SJ H Feb 4 '16 at 23:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.