Access SimpleHTTPServer from outside Network
Asked Answered
H

4

11

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?

Halden answered 18/5, 2015 at 14:16 Comment(1)
Are you asking how to make a server, or have you already written one and want it accessible from outside your network?Dorcy
M
12

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/

Monomial answered 18/5, 2015 at 14:24 Comment(5)
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.Cobia
By home's IP address you mean the one I get in whatismyip.com or by ifconfig command?Halden
Note that python -m SimpleHTTPServer works only with python 2. With python 3, you should use: python -m http.serverHilbert
@Hilbert - Thanks.Minion
probably 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 foreverAshbaugh
C
2

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
Cotten answered 17/9, 2018 at 13:48 Comment(0)
T
0

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.

Tasty answered 11/7, 2017 at 20:46 Comment(0)
A
0

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:

  1. nvm (for installing localtunnel)

  2. 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 )

Apotheosize answered 9/9, 2019 at 8:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.