I'm working with Python, Flask and Apache, and i'm stuck. when i try to visit mywebsite using www, it works fine. however, when i remove the www, the website is showing "index of /" with an empty list of files next. i've read all the possible solutions, nothing works in my case. i'm working with WSGI which means that DocumentRoot is irrelevant because i'm using the WSGIScriptAlias variable. i'm using the ServerAlias as instructed - doesn't help. i've set up 2 seperate A records in my dns options, both point to the same ip. when i ping the website with www and without it, the same ip address is showing

<VirtualHost *:80>
    ServerName mysite.com
    ServerAlias www.mysite.com
    WSGIScriptAlias / /var/www/mysite/mysite.wsgi
    <Directory /var/www/mysite/mysite/>
        Order allow,deny
        Allow from all
    Alias /static /var/www/mysite/mysite/app/static
    <Directory /var/www/mysite/mysite/app/static/>
        Order allow,deny
        Allow from all
    ErrorLog ${APACHE_LOG_DIR}/error.log
    LogLevel warn
    CustomLog ${APACHE_LOG_DIR}/access.log combined


any ideas?

This is the output of the "apachectl -S" command:

VirtualHost configuration:
*:80                   is a NameVirtualHost
         default server mysite.com (/etc/apache2/sites-enabled      /000-default.conf:1) 
     port 80 namevhost mysite.com (/etc/apache2/sites-enabled    /000-default.conf:1)
     port 80 namevhost mysite.com (/etc/apache2/sites-enabled    /mysite.conf:1)
             alias www.mysite.com
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex watchdog-callback: using_defaults
Mutex default: dir="/var/lock/apache2" mechanism=fcntl 
PidFile: "/var/run/apache2/apache2.pid"
User: name="www-data" id=33
Group: name="www-data" id=33

Seems like /etc/apache2/sites-enabled/000-default.conf matches your request first. Remote this file and it might help.


Whether to keep default virtualhost or not depends on you and what you want. If you require to have exact match with the domains you host, default virtualhost will manage all requests that goes to your server and don't belong to any domain. Example of such a request can be if you just put IP of the server to the browser.

However there are cases, where it is ok to have default virtualhost disabled. Example: You hosts several domains, all using the same document root. And you want to add/remove domains without apache reconfiguration.

In order to uderstand the virtualhost matching process, I suggest to read following document: https://httpd.apache.org/docs/2.4/vhosts/details.html

  • Yes, that was the problem. i disabled the default website and it works now. however, there are things i don't understand yet, maybe you could help. first of all, i've read in a similiar post that disabling it is a bad idea security wise. not sure why, that's why i'm asking. and isn't there a different solution to the problem if so? like to prioritize my custom config to be ahead of the default one? why am i having this problem at all while others don't? – buddha_buddha Nov 9 '16 at 20:19
  • Update the answer – Yarik Dot Nov 10 '16 at 10:22

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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