I have a user data script on an EC2 instance that installs and configures apache at launch for a Flask Rest API. All the files are pulled from my Git repo, and the VirtualHost config is as follows:
<VirtualHost *:80>
ServerName *
ServerAdmin admin@mywebsite.com
WSGIPassAuthorization On
WSGIScriptAlias / /var/www/FlaskApi/flaskapi.wsgi
<Directory /var/www/FlaskApi/FlaskApi/>
Order allow,deny
Allow from all
</Directory>
Alias /static /var/www/FlaskApi/FlaskApi/static
<Directory /var/www/FlaskApi/FlaskApi/static/>
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
However, at launch, there is no way to know which public ip address the instance will get, therefore i would like to know if there is some sort of wildcard config for a VirtualHost so there is no need to specify a ServerName or IP.
Edit: As per Jorge's suggestion, i have added the following to my start up script and it is working like a charm!
ip=$(curl http://169.254.169.254/latest/meta-data/public-ipv4)
sudo sed -i "s/replace/$ip/g" /etc/apache2/sites-enabled/FlaskApi.conf