[FIXED] Flask shows apache2 page on DNS


My flask app works when accessed via IP( but when using the dns(http://friendhub.social/), it only shows the default apache2 page.
If I try to move my own page over to /var/www/html, it will only show a directory tree


<VirtualHost *:80>
                ServerAdmin email@mywebsite.com
                WSGIScriptAlias / /var/www/social/social.wsgi
                <Directory /var/www/social/social/>
                        Options Indexes FollowSymLinks
                        AllowOverride None
                        Require all granted
                Alias /static /var/www/social/social/static
                <Directory /var/www/social/social/static/>
                        Order allow,deny
                        Allow from all
                ErrorLog ${APACHE_LOG_DIR}/error.log
                LogLevel warn
                CustomLog ${APACHE_LOG_DIR}/access.log combined
  • apache2 version: Apache/2.4.52 (Ubuntu)
  • flask: 2.2.2
  • python: 3.10.4
  • os: ubuntu 22.04.1 LTS
  • deployment on Linode


You need to set ServerName to the hostname in DNS, not the IP address.

This is because many different hostnames may be associated with a single ip address, for instance on a shared hosting platform. In the HTTP request the browser will send a header that says

Host: friendhub.social

and that’s how Apache httpd knows how to route the request.

Answered By – brunson

Answer Checked By – David Marino (Easybugfix Volunteer)

Leave a Reply

(*) Required, Your email will not be published