Apache server can be set up and accessed from ouside Network in the following way: http://lifehacker.com/124212/geek-to-live--how-to-set-up-a-personal-home-web-server I want to achieve similar functionality with python SimpleHTTPServer. How is this possible?
-
Are you asking how to make a server, or have you already written one and want it accessible from outside your network? – Scott Hunter May 18 '15 at 14:23
4 Answers
Step 1: Run this command "python -m SimpleHTTPServer". Note that python -m SimpleHTTPServer
works only with python 2. With python 3, you should use: python -m http.server
Step 2: Edit your router's configuration to forward port 8000 to the computer on which you ran the python command.
Step 3: Determine your home network's IP address, for example, 203.0.113.47
One convenient way to determine your home network's IP address is to consult any of the what-is-my-ip websites, for example https://www.whatismyip.com/.
Step 4: From outside your network, visit (for example) http://203.0.113.47:8000/

- 163,533
- 20
- 239
- 308
-
Take into account that the SimpleHTTPServer doesn't implement all the safety features of eg. Apache. The docs say it serves pages relative to the actual directory - I doubt it has many safeguards against accessing private files. I doubt that using it openly is a good idea. I might be wrong. – jcoppens May 18 '15 at 14:52
-
By home's IP address you mean the one I get in whatismyip.com or by ifconfig command? – Raghuram Vadapalli May 18 '15 at 16:03
-
Note that `python -m SimpleHTTPServer` works only with python 2. With python 3, you should use: `python -m http.server` – Sylhare Jul 07 '17 at 20:35
-
-
2probably worth mentioning that it won't work without disabling the firewall on the PC that has the server going. Otherwise the connection to the IP and port will seem to be loading forever – Emilian Cebuc Aug 26 '18 at 22:00
In case the port 8000 is blocked in your firewall, you have to open it.
For example, on RHEL/CentOS/Fedora, open port 8000 as shown below.
#firewall-cmd --permanent --add-port=8000/tcp
#firewall-cmd --reload
On Debian, Ubuntu you can allow the port as shown below.
$ sudo ufw allow 8000

- 37,420
- 30
- 139
- 188

- 79
- 9
You can either port forward your router to the specific port and use a dynamic DNS service such as no-ip to reach your server.
Or you could use a tunneling software like localtunnel.me or ngrok to forward your port to a unique URL.
Or you could create a reverse proxy or a VPN server if you own a cloud server such as AWS or DigitalOcean.

- 2,559
- 2
- 14
- 31
Yeah, localtunnel helps you in external access of python http.server. Here external access means - to access your http.server from outside the network (suppose you're in Delhi running python http.server and want your friends who are in Bangalore to see the directory contents).
Requirements:
nvm (for installing localtunnel)
use 'lt' (CLI tool) on a specific port (but remember, in order to make external access on your python http.server you need to run python -m http.server along with )

- 1
- 1
- 2