Flask shows apache2 page on DNS

Question:

My flask app works when accessed via IP(http://194.233.174.220/) 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

/etc/apache2/sites-available/social.conf:

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

||

Answers:

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
Categories: questions Tags: , , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.