How to give specific port to the specific website in ubuntu apache2

Hi,

I have Ubuntu 14.04, installed & configured apache2

And running three websites in the default port 80, those websites are working fine, but I want to run a another website in the port number of 8081, the url must be example.com:8081.

Can anyone help me, how to assign a particular port number to particular website in Ubuntu apache2 & Centos too thanks

Please advice

For example, to make the Apache server to accept requests on port 80 and different ports say 81, 82, 83 and so on…

You need to add “Listen” directives to each number of addresses and ports to your Apache configuration file as shown below.

Listen 80
Listen 81
Listen 82
Listen 83


Or else to make the requests accept on different interfaces and port numbers, you should add like this:

Listen 192.168.0.1:80
Listen 192.168.0.2:81
Listen 192.168.0.3:82
Listen 192.168.0.4:83


Apache comes with two Virtual Host’s method, one is name-based and other is IP-based, so here we going to use IP-based as our requirement is to run sites on different ports and addresses.

So, our IP-based Virtual Host’s configuration look like this:

<VirtualHost 192.168.0.1:80> ServerAdmin webmaster@website.website.com DocumentRoot "/website/vhosts/website" ServerName www.website.com ErrorLog "/website/logs/website/error_log" CustomLog "/website/logs/website/access_log" combined </VirtualHost>

<VirtualHost 192.168.0.2:81>
ServerAdmin webmaster@website1.website.org
DocumentRoot "/website1/vhosts/website1"
ServerName www.website1.org
ErrorLog "/website1/logs/website1/error_log"
CustomLog "/website1/logs/website1/access_log" combined
</VirtualHost>

<VirtualHost 192.168.0.3:82>
ServerAdmin webmaster@website2.website.org
DocumentRoot "/website2/vhosts/website1"
ServerName www.website2.org
ErrorLog "/website2/logs/website2/error_log"
CustomLog "/website2/logs/website2/access_log" combined
</VirtualHost>

<VirtualHost 192.168.0.4:83>
ServerAdmin webmaster@website3.website.org
DocumentRoot "/website3/vhosts/website1"
ServerName www.website3.org
ErrorLog "/website3/logs/website3/error_log"
CustomLog "/website3/logs/website3/access_log" combined
</VirtualHost>


Finally restart the Apache service and test the configuration of sites

/etc/init.d/apache2 restart

Test each site.. http://localhost:80/ http://localhost:81/ http://localhost:82/ http://localhost:83/
1 Like

Hi,
Modify config file of apache , then restart apache web server by
/etc/init.d/apachectl restart or /etc/init.d/httpd restart