Create and access multiple ports for Apache on Amazon EC2(aka AWSEC2) or DigitalOcean

We can do this by using the virtual host. There is two part to complete to open and configure the ports. I used port 8080 but you can use any port that is not using for any service.

 

Part 1: Add/Update Virtual Host

  1. Navigate to the sites-available directory for the configuration file

    cd /etc/apache2/sites-available/

    You can check all available configuration files by

    ls -la

  2. For updating existing configuration file choose one from the list and jump at step 5
  3. Create a virtual host that listens to 8080 or the port number that Apache is listening to.
  4. Copy the default configuration file for setting up a new one

    sudo cp 000-default.conf 8080-default.conf

    You can name the file as you like, I named it with 8080 because it will be easy for me to understand.

  5. Now open the file to edit

    sudo nano 8080-default.conf

    1. Copy below code block or Update the file like as below

      Listen 8080

      <VirtualHost *:8080>

      #ServerName http://www.your-domain.com

      ServerAdmin admin@your-domain.com

      DocumentRoot /var/www/html/path/to/project/directory

      #LogLevel info ssl:warn

      LogLevel warn

      ErrorLog //var/www/html/path/to/project/directory/logs/error.log

      CustomLog /var/www/html/path/to/project/directory/logs/access.log combined

      </VirtualHost>

  6. Enable the site with sudo a2ensite name of the conf without .conf

    sudo a2ensite 8080-default

  7. Reload the Apache first that if there is any error, we can fix that before the restart

    sudo service apache2 reload

  8. Restart the apache now if reload is successful

    sudo service apache2 restart

Check in the browser with http://www.your-domain.com:8080, if you can access then it’s done. If not then you follow Part 2 to open the port 8080.

 

Part 2: Set rule for the Port 8080 or the port you want.

  1. Go to your Amazon/DigitalOcean Console Panel
  2. Find the security group of the instance on the instances list.
  3. Go to Security Group (for AWS EC2, find it on the LHS menu) and add the rules to allow the external world to talk to the port numbers your apache is listening to. Please follow this link (for AWS EC2) to add the rules.

Inspire Me :)

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.