Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am using this command on Ubuntu but it is starting on port 8080 and I don't have another server running so I'd like it to start on port 80. I saw ways that you could set up a bash script to do something like this, but isn't there a command line flag or something simpler to specify the port?

python -m SimpleHTTPServer
share|improve this question
2  
Are you running as root? You can't listen on a port <1024 unless you have root privileges - and I would strongly advise against that. –  Nathan Osman Nov 14 '11 at 19:53

1 Answer 1

up vote 28 down vote accepted

sudo python -m SimpleHTTPServer 80

for python 3.x version, you may need :

sudo python -m http.server 80

Ports below 1024 require root privileges.

As George added in a comment, running this command as root is not a good idea - it opens up all kinds of security vulnerabilities.

However, it answers the question.

share|improve this answer
2  
I might also add that running this command as root is not a good idea - it opens up all kinds of security vulnerabilities. –  Nathan Osman Nov 14 '11 at 19:56
2  
@cwd :) The TCP/IP port numbers below 1024 are special in that normal users are not allowed to run servers on them. This is a security feaure, in that if you connect to a service on one of these ports you can be fairly sure that you have the real thing, and not a fake which some hacker has put up for you. –  jrg Nov 14 '11 at 20:17
2  
@cwd If you want to run the server on a port <1024, use iptables to route incoming connections to a port ≥1024. For testing, do something like sudo nc -l 80 (netcat). And see Why are the first 1024 ports restricted to the root user only? –  Gilles Nov 14 '11 at 23:42
1  
@jrg A port <1024 only matters if you trust the sysadmin on the server but not other users. It's near-userless outside a few local networks nowadays: most servers aren't multiuser machines. –  Gilles Nov 14 '11 at 23:43
1  
This is a related question about how to drop privileges once you've opened port 80. –  jcollado Nov 21 '11 at 22:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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