Changing the OS X Web Server Port

Some ISPs block access to port 80 (HTTP for web access) on their subscriber systems (either to discourage them running servers, or to block the old Slapper worm.)

You'll need admin access. Open the /private/etc/httpd/httpd.conf file in a text editor (TextEdit will do, Unix editors vi or emacs from the Terminal might be better.) Unfortunately, the "/private" and "/etc" folders are invisible in OS X's Finder, so you can't easily locate the httpd.conf file with Finder. A utility such as File Buddy can let you find invisible folders and files.

First, you will need to use the Terminal (/Applications/Utilities folder) to change the access on the httpd.conf file so your admin account can edit it. Use the command "sudo chmod 666 /private/etc/httpd/httpd.conf" and press RETURN:

Terminal sudo chmod 666 /private/etc/httpd/httpd.conf

You can then use any Unix text editor (vi, emacs, pico, ed...) you like to edit the file. Or, you can use any "cocoa" Text Editor application's "Open..." from the File menu, and have it access the hidden folder by typing its name.

To access the "Go to the Folder" shortcut, type a slash (/) when the Open File dialog appears, then enter the folder's pathname, "/private/etc/httpd" and click Goto.

Open Folder httpd

Once the folder's content is displayed, pick file httpd.conf.

Open File httpd.conf

Find the lines:

#
# Port: The port to which the standalone server listens. For 
# ports < 1023, you will need httpd to be run as root initially. 
#
Port 80 
Change that port number from 80 to 8080 (anything will do, 8080 is common choice):
#
# Port: The port to which the standalone server listens. For 
# ports < 1023, you will need httpd to be run as root initially. 
#
Port 8080 
Save the file.

Use the Terminal (/Applications/Utilities folder) again to change the access on the httpd.conf file back to its original value. Use the command "sudo chmod 644 /private/etc/httpd/httpd.conf" and press RETURN:

Terminal sudo chmod 644 /private/etc/httpd/httpd.conf

Restart the web server (so it re-reads that file you edited.) Go to System Preferences, Sharing pane, Services tab and select Personal Web Sharing, click Stop , wait a minute for it to stop , click Start again (that lets the Apache webserver restart with the new port number.)

Open that port (8080) in the Mac's Firewall (OS X opens port 80 automatically when you run the web server, but you need to open the new port manually like that.): Go to System Preferences, Sharing pane, Firewall tab. Make a New entry. Set port-name pull-down to "Other"

Firewall New Port dialog

Then enter port number 8080 for the alternate web server address.

Firewall New Port dialog

Check that the new 8080 port has the "Allow" box checked:

Firewall New Port dialog

Go to the Router's Port Forwarding configuration screen and forward port 8080 to your Mac's IP Address just as you forwarded port 80 earlier.

E.g. on the LinkSys, visit URL http://192.168.1.1 in your browser, go to the Advanced settings, Forwarding screen, and enter TCP forwarding for port 8080 (and Enable it, then check Apply):

LinkSys Port Fwd 8080

When you access the server now, you need to spcify that you use a port other than the default port, 80.

Access the server now as http://your.public.ip.address:8080/~username/

For example:

Safari :8080 URL

THE END


Visit my Port Forwarding walk-through