-3

We would appreciate any vectors to solve the following issue with accessing our Web products via URLs. We would like to access three products through port 80 on our hosted server that has one public IP. They will be accessed at different points of time so we are using a single port for all of them. How could we access these products via the following URLs? Can it be achieved through Apache Web server configuration below? Or, do we need a local DNS server in addition to Apache Web server configuration?

Products to be accessed via URLs:

http://<Our.Server.Fully.Qualified.Domain.Name.com>/product1
http://<Our.Server.Fully.Qualified.Domain.Name.com>/product2
http://<Our.Server.Fully.Qualified.Domain.Name.com>/product3

In /etc/hosts file, we have added

10.10.10.100 product1 product2 product3

Apache Web server’s vhosts.conf

<VirtualHost 10.10.10.100:80>
    DocumentRoot "/usr/local/product1"
    ServerName product1
    ServerAdmin admin@Our.Server.Fully.Qualified.Domain.Name.com
    ErrorLog "/usr/local/apache2/logs/error_log"
    TransferLog "/usr/local/apache2/ logs/access_log"
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "/usr/local/product2"
    ServerName product2
    ServerAdmin admin@Our.Server.Fully.Qualified.Domain.Name.com
    ErrorLog "/usr/local/apache2/logs/error_log"
    TransferLog "/usr/local/apache2/ logs/access_log"
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "/usr/local/product3"
    ServerName product3
    ServerAdmin admin@Our.Server.Fully.Qualified.Domain.Name.com
    ErrorLog "/usr/local/apache2/logs/error_log"
    TransferLog "/usr/local/apache2/ logs/access_log"
</VirtualHost>

EDIT: As @arober11’s solution worked for us, we have extended the configuration to three additional products that are distributed across two servers (virtual machines, VM-1, VM-2) on the same physical server:

(1) product4 is in a different directory (/usr/local/dir4/product4) of VM-1 (products1/2/3 are in /usr/local).

(2) product5 is in a different server VM-2 in /usr/local/dir5/product5.

(3) product6 is in VM-2 in /usr/local/dir6/product6.

We understand a VirtualHost container can have only one ServerName, which, in turn, can have only one DocumentRoot. Therefore, for each of the products 4/5/6, do we have to:

(i) Create new VirtualHosts with their respective IP and Port numbers?

(ii) Add ServerNames to /etc/hosts of VM-1 and VM-2 respectively. (Or, is this redundant even in this expanded deployment?)

---------Details-----------

Both the VMs are accessed by the same external IP. Private IPs of Virtual Machines and their DNS pointers are:

VM-1:  http://<Our.Server.Fully.Qualified.Domain.Name.com> -> 10.10.10.100 (Port 80)
VM-2:  http://<Our.Server.Fully.Qualified.Domain.Name.com:9080> -> 10.10.10.200 (Port 9080)

The products are to be accessed via:

http://<Our.Server.Fully.Qualified.Domain.Name.com>/product4  (in VM-1)
http://<Our.Server.Fully.Qualified.Domain.Name.com>:9080/product5 (in VM-2)
http://<Our.Server.Fully.Qualified.Domain.Name.com>:9080/product6 (in VM-2)

(1) Product 4 in VM-1.

<VirtualHost *:80>
DocumentRoot "/usr/local/dir4/product4"
ServerName product4
ServerAdmin admin@Our.Server.Fully.Qualified.Domain.Name.com
ErrorLog "/usr/local/apache2/logs/error_log"
TransferLog "/usr/local/apache2/ logs/access_log"
<Directory />

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

(2) For Product 5 (which is in VM-2)

<VirtualHost 10.10.10.200:9080>
DocumentRoot "/usr/local/dir5/product5"
ServerName product5
ServerAdmin admin@Our.Server.Fully.Qualified.Domain.Name.com
ErrorLog "/usr/local/apache2/logs/error_log"
TransferLog "/usr/local/apache2/ logs/access_log"
<Directory />
DirectoryIndex index.html
</Directory>
</VirtualHost>

(3) For Product 6 (which is in VM-2)

<VirtualHost 10.10.10.200:9080>
DocumentRoot "/usr/local/dir6/product6"
ServerName product6
ServerAdmin admin@Our.Server.Fully.Qualified.Domain.Name.com
ErrorLog "/usr/local/apache2/logs/error_log"
TransferLog "/usr/local/apache2/ logs/access_log"
<Directory />
DirectoryIndex abc.jsp
</Directory>
</VirtualHost>

1 Answers1

0

You can lose your redundant /etc/hosts entry, as you just need the single VirtualHost, with a DocRoot pointed at the parent directory of your sub-directories eg.

<VirtualHost *:80>
  DocumentRoot "/usr/local/"
  ServerName Our.Server.Fully.Qualified.Domain.Name.com
  ServerAdmin admin@Our.Server.Fully.Qualified.Domain.Name.com
  ErrorLog "/usr/local/apache2/logs/error_log"
  TransferLog "/usr/local/apache2/logs/access_log"
</VirtualHost>
arober11
  • 1,969
  • 18
  • 31
  • Thank you @arober11. Your suggestion helped us solve this issue. We have an EDIT to post seeking inputs. – Susheel Jalali Aug 17 '15 at 08:08
  • Is this question in some pending state after the EDIT, waiting for approval or unblocking? Clicked on an upvote on the lone answer, and as per guidelines, waiting for some more answers before accepting the best one. After reading all guidelines, they are all being complied with (hopefully). – Susheel Jalali Aug 18 '15 at 11:44