# How to: run custom web server on port 80



## slamet (Feb 15, 2012)

I just got myself a VPS with fresh FreeBSD 9 installed.  I wrote a simple hello world custom web server.  It ran ok listening on port 8080 to serve pages to internet visitors, i.e. http://domain:8080 served up the page.  

But when I switched it to listen to port 80, I got:

```
starting .. port # :80
```
And then the process exited without any error message.  And http://domain failed cause the web server is not up.

I assume if I get the web server to work on port 80, then http://domain will serve up pages.

Q1: If the assumption is correct, then what do I need to set to let it listen on port 80?

Q2: If the assumption is incorrect, then how do I serve http://domain without visitor having to specify port?

The fresh install had /etc/services showing http on port 80 line.

Thanks.


----------



## SirDice (Feb 15, 2012)

Only root is able to open a listening port below 1024.


----------



## slamet (Feb 16, 2012)

Oh ..

Thanks! Running the process with root access obviously got my http://domain to serve pages as you mentioned @SirDice.

I have looked up man pages related to services and I could not find (or understand) if there is a configuration option / file whereby I can set non-root to access port 80.  Is this possible (short of recompiling, which I am so not qualified)?


----------



## slamet (Feb 16, 2012)

Forgot to mention that I also looked up jail in the handbook.  It looks overly complicated for what I need.

I suppose PF is also an option to redirect inbound port 80 traffic to port higher than 1024, but I do not know if this is the way to go either.  I am looking for minimal learning curve just to get started.

Thanks if anybody has any tip.


----------



## SirDice (Feb 16, 2012)

slamet said:
			
		

> I have looked up man pages related to services and I could not find (or understand) if there is a configuration option / file whereby I can set non-root to access port 80.  Is this possible (short of recompiling, which I am so not qualified)?


Stop looking for it. It doesn't exist. _ALL_ unix and unix-like operating systems have this 'limitation'.

Apache (and all other web services) open a listening port as root and then drop their privileges as a security precaution.


----------



## slamet (Feb 17, 2012)

Makes sense now.  Thanks.


----------

