34

I want apache to do this >

mydomain.com:80  --- opens var/www1
mydomain.com:81  --- opens var/ww2
mydomain.com:82  --- opens var/www3

Problem is I don't know if those ports are open on Linux (how do I check?)

And if they're not how do I open them in the firewall and get apache to listen?

I tried doing this

> iptables -A RH-Firewall-1-INPUT -m  NEW -m tcp -p tcp –dport 81 -j ACCEPT
iptables v1.3.5: Couldn't load match `NEW':/lib64/iptables/libipt_NEW.so: cannot open shared object file: No such file or directory

and I checked the ports... looks like httpd is listening... but I don't know why I can't hit my URL

> netstat -tulpn | less
tcp        0      0 :::80       :::*      LISTEN      6840/httpd
tcp        0      0 :::81       :::*      LISTEN      6840/httpd
tcp        0      0 :::82       :::*      LISTEN      6840/httpd
Dave M
  • 4,514
  • 22
  • 31
  • 30
qodeninja
  • 2,753
  • 10
  • 32
  • 33

3 Answers3

57

To expand on Jeff's answer you'll need something like this in your apache configuration

Listen 80
Listen 81
Listen 82

# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80

<VirtualHost *:80>
DocumentRoot /var/www1
ServerName www.example1.com
</VirtualHost>

NameVirtualHost *:81
<VirtualHost *:81>
DocumentRoot /var/www2
ServerName www.example2.org
</VirtualHost>


NameVirtualHost *:82
<VirtualHost *:82>
DocumentRoot /var/www3
ServerName www.example3.org
</VirtualHost>
sreimer
  • 2,218
  • 15
  • 17
  • 1
    I did exactly that ... but still no love – qodeninja Mar 13 '11 at 18:29
  • can you telnet to any of these ports locally and/or remotely? – sreimer Mar 15 '11 at 14:07
  • 1
    `NameVirtualHost` has no effect when used with Apache 2.4 – Vahid Amiri Mar 26 '17 at 18:24
  • NameVirtualHost seems to have an effect for me, and I am using Apache 2.4: without NameVirtualHost, "" is not enough to prevent the VirtualHost from answering on other ports. – rsethc Mar 26 '18 at 23:56
  • This will make Apache server crash with error `Error: Apache shutdown unexpectedly. This may be due to a blocked port,......` if `Listen 80` directive is enabled in `httpd.conf` file. So it must be only kept in one file and removed from the other. – hiddeneyes02 May 06 '22 at 06:56
11

Step 1: Configure Apache to Listen on each of the ports you want to service.

Step 2: Set up a Virtual Host configuration for each port you want to service.

Jeff Albert
  • 1,987
  • 9
  • 14
7
Listen 81
Listen 82

<VirtualHost *:80>
 DocumentRoot /var/www1
 ServerName mydomain.com
</VirtualHost>
          //access --  mydomain.com:80
<VirtualHost *:81>
 DocumentRoot /var/www2
 ServerName mydomain.com
</VirtualHost>
          //access --  mydomain.com:81
<VirtualHost *:82>
 DocumentRoot /var/www3
 ServerName mydomain.com
</VirtualHost>
          //access --  mydomain.com:82