Search code examples
apacheubuntuportvirtualhostlamp

apache2 VirtualHost on a new port not working


I just installed LAMP on my Ubuntu machine, and it works fine when I access it. I want to add a virtual host on another port, port 1337, that goes to the directory /var/www/flag-1/. In order to do this, I take the following steps:

  1. cd /etc/apache2/sites-available/
  2. Created a file flag-1.conf
  3. Added contents:
<VirtualHost *:1337>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/flag-1/
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
  1. At the top of /etc/apache2/ports.conf, after Listen 80, added Listen 1337
  2. Enabled the vhost site by doing a2ensite flag-1.conf
  3. Reloaded apache service apache2 restart

When I access the site with port 1337, it just loads indefinitely. The default port still works fine, and I don't have UFW enabled. No errors, nothing in access.log or error.log is outstanding.

Any help is appreciated. Thanks!


Solution

  • Figured it out -- I was using Google Cloud Platform and they blocked port 1337, I just had to manually allow TCP through it.

    If you're wondering, the command was

    gcloud compute firewall-rules create allow-port-1337 --allow tcp:1337 --description="Allow port 1337 to be accessed"