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
CodePudding user response:
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.