1

Currently I have an Apache2 listening on Port 80. This is configured in /etc/apache2/listen.conf

In /etc/apache2/conf.d I have the normal configuration files and:

site1.conf, site2.conf and site3.conf files.

Each conf file is configured very similar :

Alias /site1 /home/user/www/site1/

AddHandler cgi-script cgi

<Directory "/home/user/www/site1/">
  AllowOverride All
  Options +ExecCGI

  <IfModule mod_authz_core.c>
    Require all granted
  </IfModule>

  <IfModule !mod_authz_core.c>
    Order allow,deny
    Allow from all
  </IfModule>

  DirectoryIndex index.cgi
</Directory>

So going to my browser I can enter:

http://10.10.0.1/site1 and get site1, http://10.10.0.1/site2 and get site2 etc

This works fine internally.

I'd now like to allow site2 and site3 to be accessed externally.

If I open port 80 on my router and route it to 10.10.0.1 then all sites are available.

I've added 8080 & 8888 to /etc/listen.conf and edited site2.conf as :

<VirtualHost *:8080>
 Alias /site2 /home/user/www/site2/

    AddHandler cgi-script cgi

    <Directory "/home/user/www/site2/">
      AllowOverride All
      Options +ExecCGI

      <IfModule mod_authz_core.c>
        Require all granted
      </IfModule>

      <IfModule !mod_authz_core.c>
        Order allow,deny
        Allow from all
      </IfModule>

      DirectoryIndex index.cgi
    </Directory>
</VirtualHost>

and site3 the same but setting the VirtualHost to *:8888

This works. I can access site2 only on 8080 and site3 only on 8888 BUT

I can also access site1 on port 8080 and port 8888

What I want is :

  • site1 is only available from port 80
  • site2 is only available from port 8080
  • site3 is only available from port 8888

The router only has 8080 and 8888 open and routing.

Any idea how I can do this ?

Thanks

1 Answer 1

1

I've never tried I just tested using Apaches DocumentRoot directive without a corresponding ServerName named host - and I got it working on my machine.
The idea is to try and get the virtual host to match to a filepath, try replacing this:

Alias /site2 /home/user/www/site2/

with

DocumentRoot /home/user/www/site2

Apache documentation says

The DocumentRoot should be specified without a trailing slash.

so you get

<VirtualHost *:8080>
 DocumentRoot /home/user/www/site2

    AddHandler cgi-script cgi

    <Directory "/home/user/www/site2/">
      AllowOverride All
      Options +ExecCGI

      <IfModule mod_authz_core.c>
        Require all granted
      </IfModule>

      <IfModule !mod_authz_core.c>
        Order allow,deny
        Allow from all
      </IfModule>

      DirectoryIndex index.cgi
    </Directory>
</VirtualHost>

Try on one virtualhost website combination, if it works repeat on the others. - dont forget to restart apache after you modify the vhosts - you will probably have to if you change the Listen directive.

Apache has a guide on running multiple website on different ports.
This is based on apache 2.2 and docs say

[you must use] NameVirtualHost x.x.x.x:8080 - without the NameVirtualHost name:port or you try to use the Listen directive, your configuration will not work.

I tested on 2.4 on Ubuntu without the NameVirtualHost and it worked fine for me

4
  • Thanks I will try this. One of my conf files has multiple aliases, each going to different locations locally. How would I add them ?
    – MacMan
    Oct 22, 2015 at 11:04
  • I would just try get the virtualhost matching to the file paths first, I had to make multiple attempts configuring apache to get it to work on my machine, including tracking, then responding to, apache's error logs. Then try adding your aliases - and again track log output - if you cant sort it then post another question providing all details Oct 22, 2015 at 11:11
  • Thanks _ I've got this working for one site using port 80 and another using port 8080. I have a slight issue with a 3rd site. But will raise that as a new question.
    – MacMan
    Oct 29, 2015 at 11:25
  • cool, glad you got it working! Oct 29, 2015 at 11:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .