Baptiste Pernet
Baptiste Pernet

Reputation: 3384

Apache port and url

I want to have several sites on my local machine, associated to specific port in my apache configuration. I don't even know if what I want is possible to do, or if I have the good way of thinking. May be I need other tools, so please, can you explain me ?

I have my dev machine with several site working on it, in my hosts file I put:

127.0.0.1        local.site1.com
127.0.0.1        local.site2.com

In appache configuration, I have these virtual hosts:

Listen 8081
Listen 8082

<VirtualHost *:8081>
  ServerName local.site1.com
  ServerAlias local.site1.com
  DocumentRoot "C:/site1"
</VirtualHost>

<VirtualHost *:8082>
  ServerName local.site2.com
  ServerAlias local.site2.com
  DocumentRoot "C:/site2"
</VirtualHost>

Do you know what should I do to have ?

Now, my configuration looks useless, because http://local.site1.com opens port 80, and http://local.site2.com:8081 goes to site1.

Upvotes: 0

Views: 499

Answers (1)

Daniel Scott
Daniel Scott

Reputation: 7913

Why do you want them running on different ports? You don't need to do that to get what you want.

You can use NameVirtualHosts and run both sites on the same port, and the server will serve the correct site based on the domain name used in your browser.

http://httpd.apache.org/docs/2.2/vhosts/name-based.html

Example

NameVirtualHost *:80

<VirtualHost *:80>
  ServerName local.site1.com
  ServerAlias local.site1.com
  DocumentRoot "C:/site1"
</VirtualHost>

<VirtualHost *:80>
  ServerName local.site2.com
  ServerAlias local.site2.com
  DocumentRoot "C:/site2"
</VirtualHost>

Upvotes: 1

Related Questions