3

Possible Duplicate:
Can I specify a port in an entry in my /etc/hosts on OS X?

I have NGINX working on port 80, and APACHE on port 8080 (Listen 8080).

On Apache I have several Virtualhosts over port 8080.

Before (when I had apache running on port 80) I had the domain->ip mapping on the /etc/hosts file:

127.0.0.1 my-domain.dev

But now that I also need to specify the port, how should I do it?

I am running Mac Os 10.7 (Lion) and my VirtualHost looks like this:

NameVirtualHost *:8080

<VirtualHost *:8080>
    ServerName localhost
    DocumentRoot "/Library/WebServer/Documents"
</VirtualHost>

<VirtualHost *:8080>
    ServerName my-domain.dev
    DocumentRoot "/path/to/my/deploy/folder"
        <Directory "/path/to/my/deploy/folder">
            Order allow,deny
            Allow from all
            AllowOverride All       
        </Directory>
</VirtualHost>

(...)
Guille Lopez
  • 31
  • 1
  • 1
  • 3
  • No, you do not need to specify the port in the /etc/hosts file. What are trying to do - are you trying to access port 80 and 8080 for each application respectively locally? – Rilindo Nov 06 '11 at 01:41

3 Answers3

4

You can't. /etc/hosts works similarly to DNS and doesn't handle ports at all. It simply resolves a name to an IP address. You'll have to put :8080 at the end of the address.

MDMarra
  • 100,183
  • 32
  • 195
  • 326
1

You can't write port in hosts, and with old settings in hosts changed port will be accessible, you just have to add :8080 to URL.

If you want leave server on 8080 port but make this port default for http instead of 80 (in order to use old-style URLs), you have to add SRV records for zone-definition (and have running DNS-server, even local, with your domains, defined in this server)

Lazy Badger
  • 3,067
  • 14
  • 13
0

As others have said you can't use the hosts file to define the port that Apache is listening on. the reason you didn't have to supply a port when Apache was listening on port 80 is becase port 80 is the default port for the http protocol. If you don't want to have to specify the port number in your URLs then consider setting nginx to reverse proxy for the apache sites.

user9517
  • 114,104
  • 20
  • 206
  • 289