How to run a temporary http server without installing Nginx / Apache in Ubuntu

Sometimes we only want to open HTTP ports temporarily, here is how:

If you have enabled ufw, add ufw rule to allow the port being used by HTTP server. For example. to open port 3000 for HTTP server:

1
sudo ufw allow from any to any port 3000

Now check all ufw rules:

1
sudo ufw status numbered

Go to your website folder. Create html files, e.g. index.html if you don’t have them.

Run the following command to start your web server by typing:

1
python3 -m http.server 3000

Now you can access that page in your browser.

After running it, delete the rule (the number can be found from above command, e.g. sudo ufw status numbered):

1
sudo ufw delete THE_RULE_NUMBER
Share