Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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>

(...)
share|improve this question

marked as duplicate by quanta, Scott Pack, MikeyB, Bill Weiss, Tom O'Connor Nov 7 '11 at 0:35

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
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 6 '11 at 1:41

4 Answers 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.

share|improve this answer

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)

share|improve this answer

You put it in your httpd.conf not /etc/hosts

Listen *:8080
<VirualHost *:8080>
     stuff here
</VirtualHost>
share|improve this answer
    
What makes you think he has that in the hosts file? –  MDMarra Nov 6 '11 at 2:53

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.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.