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
  • 4
    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. Nov 14, 2011 at 19:53

2 Answers 2


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.

  • 8
    I might also add that running this command as root is not a good idea - it opens up all kinds of security vulnerabilities. Nov 14, 2011 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, 2011 at 20:17
  • 4
    @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? Nov 14, 2011 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. Nov 14, 2011 at 23:43
  • 3
    This is a related question about how to drop privileges once you've opened port 80.
    – jcollado
    Nov 21, 2011 at 22:43

Do something like :

python -m SimpleHTTPServer 50505

Where 50505 is the port number.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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