Apache on multiple ports

Question : How do i run apache on multiple ports?

 

Similar to exim and other services, apache do have capability to run on multiple ports. All you have to do it to edit the httpd.conf file and added a new Listen line which the specific port no which you like to run.

 

  • # vi /etc/httpd/conf/httpd.conf

Add below the Listen 80 line (for example if you want to run on port 8080)

 

  • Listen 8080

 

Restart the service httpd service.

 

Question : Is it possible to run a single Vhost on different port (example : 8080) and others on the normal port?

 

Yes, it is possible but is vhost should have a separate(dedicated) ip address, edit the httpd.conf

 

  • # vi /etc/httpd/conf/httpd.conf

Look and add the following line below the Listen 80 (for example the vhost dedicated ip is 192.168.1.1)

 

  • Listen 192.168.1.1:8080

 

Look below and change the NameVirtualHost 192.168.1.1:80 to NameVirtualHost 192.168.1.1:8080

 

And also in the virtualhost.

 

  • <VirtualHost 192.168.1.1:8080>

 

And this will make the web sever to listen the other ips on port 80 and the 192.168.1.1 ip to 8080. This is especially useful for if you are planning to run varnish cache for a specific domain/vhost which will listen on port 80 (ie.. on ip 192.168.1.1) and apache on port 8080.

 

Good Luck!