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.
Best Answer
Here are your configs; reformatted my me for readability:
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 likeexample.com
then it is choking, correct? If that is the case what you need to do is set the virtual host lines like this:And this for HTTPS:
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: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 thenServerAlias
allows the config to capture other variants ofwww.example.com
such asexample.com
orwww.example.net
.