I want to start a web2py server so that it can be accessed externally to the hosting server.
I've read this http://web2py.com/books/default/chapter/29/03
By default, web2py runs its web server on 127.0.0.1:8000 (port 8000 on
localhost), but you can run it on any available IP address and port.
You can query the IP address of your network interface by opening a
command line and typing ipconfig on Windows or ifconfig on OS X and
Linux. From now on we assume web2py is running on localhost
(127.0.0.1:8000). Use 0.0.0.0:80 to run web2py publicly on any of your
network interfaces.
but I can't find how to "Use 0.0.0.0:80" ? There doesn't seem to be a command line argument which would do that.
Thanks
EDIT: I should say the server in question does not have a GUI - I'm aware there's some sort GUI based admin facilties for web2py but that's out of the question here.
EDIT2: Just in case this is not clear (and on the offchance it makes any difference - which I doubt) I'm running the server like this :
sudo python web2py.py
not via wsgi/apache or the like.
python web2py.py --ip 0.0.0.0
just works fine but the log message will point you to an invalid address:
please visit:
http://0.0.0.0:8000
alternatively you can use ethernet interface ip but it will not listen also on localhost
What may help you is the fact that you can select the public ip when the server gui pops up asking for the admin password.
do the following in a terminal
install ufw with apt
add 8000 to firwall.
ufw allow 8000/tcp
ufw allow 8000/tcp
navigate to where your downloaded web2py is and cd web2py
use nano serverstartup.sh and add the line bellow
python2.7 web2py.py -a 'Server admin passwrod' -c server.crt -k server.key -i your device IP address -p 8000
change the the server admin password to any password of your choice.
chmod +x serverstartup.sh
run ./serverstartup.sh in your terminal
that is it. you can stop the server by holding control and c key on your keboard.
Related
I cannot seem to figure out why I cannot access my local django webserver from an outside device. I suspect it has to do with port forwarding but none of my attempts to solve it seem to work.
I started by following the suggestions posted here How to access the local Django webserver from outside world by launching the server using python manage.py runserver 0.0.0.0:8000 and by entering <my-ip-address>:<port> in my external device' browser. This did not work, so I tried to explicitly make sure port forwarding was enabled by adding the following lines to iptables.
iptables -A INPUT -p tcp --dport 8000 -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -p tcp --sport 8000 -m conntrack --ctstate ESTABLISHED -j ACCEPT
netfilter-persistent save
Still, I'm not able to access the local webserver. No error messages show up, the browser just tells me that the address took too long to respond. I've tried to do the above but this time with port 80 and using sudo when needed without avail. In addition I've tried to use this line ALLOWED_HOSTS = ['*'] as suggested by multiple users.
I've tried to investigate whether the application is really running on the indicated port using lsof -i which shows several PYTHON lines but I'm not sure what else I'm supposed to look for to see whether things are running correctly. Finally, I've disabled my firewall on my external device, which didn't help either.
Can anyone point me to a direction to find out what's wrong?
EDIT: to clarify, I can access the server perfectly fine from the same device where the local server is running.
I followed the instructions here to run Django using the built-in webserver and was able to successfully run it using python manage.py runserver. If I access 127.0.0.1:port locally from the webserver, I get the Django page indicating it worked.
I realize the Django webserver is not a production server, but it's important for me for testing purposes to be able to access it from the outside world -- i.e. not from a web browser on the server, but from a different computer.
I tried:
http://mywebserver:port_django_runs_on
but it did not work. I also tried using the IP instead (based on ifconfig) to access:
http://myipaddress:port_django_runs_on
which did not work either.
The web server is running so it must be accessible from the outside, I'm just not sure how. I am running Linux with Apache, though I have not configured Django with Apache.
Any ideas on how to do this?
You have to run the development server such that it listens on the interface to your network.
E.g.
python manage.py runserver 0.0.0.0:8000
listens on every interface on port 8000.
It doesn't matter whether you access the webserver with the IP or the hostname. I guess you are still in your own LAN.
If you really want to access the server from outside, you also have to configure your router to forward port e.g. 8000 to your server.
Check your firewall on your server whether incoming connections to the port in use are allowed!
Assuming you can access your Apache server from the outside successfully, you can also try this:
Stop the Apache server, so that port 80 is free.
Start the development server with sudo python manage.py runserver 0.0.0.0:80
I had to add this line to settings.py in order to make it work (otherwise it showed an error when accessed from another computer)
ALLOWED_HOSTS = ['*']
then ran the server with:
python manage.py runserver 0.0.0.0:9595
Also ensure that the firewall allows connections to that port
Pick one or more from:
Your application isn't successfully listening on the intended IP:PORT
Because you haven't configured it successfully
Because the user doesn't have permission to
Your application is listening successfully on the intended IP:PORT, but clients can't reach it because
The server local iptables prevents it.
A firewall prevents it.
So, you can check that your application is listening successfully by running lsof -i as root on the machine and look for a python entry with the corresponding port you've specified.
Non-root users generally cannot bind to ports < 1024.
You'll need to look at iptables -nvL to see if there's a rule that would prevent access to the ip:port that you are trying to bind your application to.
If there is an upstream firewall and you don't know much about it, you'll need to talk to your network administrators.
just do this:
python manage.py runserver 0:8000
by the above command you are actually binding it to the external IP address.
so now when you access your IP address with the port number, you will be able to access it in the browser without any problem.
just type in the following in the browser address bar:
<your ip address>:8000
eg:
192.168.1.130:8000
you may have to edit the settings.py
add the following in the settings.py in the last line:
ALLOWED_HOSTS = ['*']
hope this will help...
For AWS users.
I had to use the following steps to get there.
1) Ensure that pip and django are installed at the sudo level
sudo apt-get install python-pip
sudo pip install django
2) Ensure that security group in-bound rules includ http on port 80 for 0.0.0.0/0
configured through AWS console
3) Add Public IP and DNS to ALLOWED_HOSTS
ALLOWED_HOSTS is a list object that you can find in settings.py
ALLOWED_HOSTS = ["75.254.65.19","ec2-54-528-27-21.compute-1.amazonaws.com"]
4) Launch development server with sudo on port 80
sudo python manage.py runserver 0:80
Site now available at either of the following (no need for :80 as that is default for http):
[Public DNS] i.e. ec2-54-528-27-21.compute-1.amazonaws.com
[Public IP] i.e 75.254.65.19
I'm going to add this here:
sudo python manage.py runserver 80
Go to your phone or computer and enter your computers internal IP (e.g 192.168.0.12) into the browser.
At this point you should be connected to the Django server.
This should also work without sudo:
python manage.py runserver 0.0.0.0:8000
UPDATED 2020
TRY THIS WAY
python manage.py runserver yourIp:8000
ALLOWED_HOSTS = ["*"]
You need just to allow any hosts :
settings.py :
ALLOWED_HOST = ['*']
Run your server :
python3 manage.py runserver 0.0.0.0:8000
If you want to connect android app just add internet permission in AndroidManifest
It's work for me ;)
open terminal
type : ifconfig
check results of ifconfig command
use the inet IP .. should look like this.. 192.168.1.121 or similar 192.168.x.x.
now runserver like you normally do but this time specify the inet IP
python3 manage.py runserver 192.168.x.x:8000 (replace the x with your inet)
also
on settings.py
ALLOWED_HOSTS = ['*']
install ngrok in terminal
sudo apt-get install -y ngrok-client
after that run:
ngrok http 8000
or
ngrok http example.com:9000
If you are using Docker you need to make sure ports are exposed as well
I'm using django's builtin server to develop a site and I want other computers in the same network I'm on to be able to access the server using the local IP address.
I have seen many posts about this and after trying all suggestions it's still not allowing other computers in my network to access the site.
I run the server using
python manage.py runserver 0.0.0.0:8000
and have already opened port 8000 as you can see in the following image.
I'm running Django 1.4.2, Python 2.7.3, Fedora 18 on kernel 3.8.11-200
Any help is highly appreciated. Thanks.
Use python manage.py runserver <ip>:<port>
For example,my IP is 192.168.0.100 and I want to run django app on port 80,I have to do
[sudo] python manage.py runserver 192.168.0.100:80
My port 80 needed root permissions,maybe because I have other applications accessing it.
You also have to add the IP address to ALLOWED_HOSTS list in settings.py
By doing this all clients in the 192.168.0 network will be able to access the site at 192.168.0.100
You're starting Django as needed - it will accept connections from anywhere as soon as the connections get to it.
Check your firewall and make sure it's allowing 8000 port connections. Something like this should work:
iptables -I INPUT -p tcp -m tcp --dport 8000 -j ACCEPT
Optionally you will need to extend the INTERNAL_IPS variable in the setting to allow remote debugging: https://docs.djangoproject.com/en/dev/ref/settings/#internal-ips .
skarap is correct. If your network is configured correctly and your django application with pytho9n manage.py runserver 0.0.0.0:8000 and you still can't access your django app from the VM host there is almost certainly a firewall issue. The illustration above is good if you are running iptables.
I deployed CentOS 7 on a virtualbox VM from a Windows 7 host. I didn't know that this distribution uses firewalld, not iptables to control access.
if
ps -ae | grep firewall
returns something like
602 ? 00:00:00 firewalld
your system is running firewalld, not iptables. They do not run together.
To correct you VM so you can access your django site from the host use the commands:
firewall-cmd --zone=public --add-port=8000/tcp --permanent
firewall-cmd --reload
Many thanks to pablo v on the http://www.scriptscoop.net site for pointing this out.
You have to add the server IP to the ALLOWED_HOSTS in the settings.py
set firewall rules with
$ sudo ufw enable
$ sudo ufw allow 8000
type ipconfig
copy addr under inet
do python3 manage.py runserver your_inet_addr:8000
After cding to my folder I enter
python -m SimpleHTTPServer
and get
Serving HTTP on 0.0.0.0 port 8000 ...
in reply. But when I hit http://0.0.0.0:8000/test.html I get a page not found error.
I've also tried
pushd /path/you/want/to/serve; python -m SimpleHTTPServer; popd
taken from this question
When I hit ls I can see the file and the directory. Anyone know what I'm doing wrong?
I think the other two answers are trying to make it clear that 0.0.0.0 is not the URL you should be visiting. When a Python web server (like cherrypy for instance) says it is serving on 0.0.0.0 it means it is listening for all TCP traffic that ends up at that machine no matter the hostname or IP that was requested. But, if you change it such that the socket listens on 127.0.0.1 or 'localhost', then unless the request was specifically to that IP/hostname, it won't respond to the request. For example, many times you can use your machine name instead of localhost (ubuntu allows this for example). If your machine name is 'brian' and you have a server listening on 0.0.0.0:8080, you should be able to reach that server with http://brian:8080. But if that server is listening on 'localhost', even though 'brian' is set to point to 'localhost', the server won't receive the message.
You also need to be sure the file really is in the directory you are running the command from. Otherwise, the 404 response is actually correct :)
Good luck!
Have you tried http://127.0.0.1:8000/ ?
:)
You must type in the ip-address of the computer your connecting to for example 192.168.0.2:8000 Change that to the ip-address of your server.
Try browsing to http://localhost:8000/test.html or http://127.0.0.1:8000/test.html (those two should be exactly the same thing as long as your hosts file isn't all crazy-like).
0.0.0.0 is usually used by Windows as the "Not connected" IP, and can also be used as a sort of wildcard for when dealing with IPs. I am a bit confused at why your HTTP server is trying to host on 0.0.0.0, though. You may need to edit some config files and set that to 'localhost' or '127.0.0.1'.
Try to host over localhost may it help you instead of trying it on http://0.0.0.0/ like this way: python -m http.server 8000 --bind 127.0.0.1
create a directory e.g. mkdir HTTPServer_dir
move inside the folder cd HTTPServer_dir
typing the command (according to python version) python -m SimpleHTTPSever 8000
(or the port you want)
go on a browser and type http://127.0.0.1:8000/
Done !!!
You could make a simple index.html page inside the HTTPServer_dir so you can see an html page instead of directory listing
Run ifconfig on Linux or ipconfig on Windows to find the ip address of the server.
$ sudo ifconfig
wlan0 Link encap:Ethernet HWaddr 30:3a:64:b3:be:6a
inet addr:192.168.1.103 Bcast:192.168.1.255 Mask:255.255.255.0
Here in case the url would be:
http://192.168.1.103:8000/test.html
try this in python3
python -m http.server 8000 --bind 127.0.0.1
and in your browser this url:
http://127.0.0.1:8000/
Sometimes the same port number is used by some other service. So we can try with some other port like
python -m SimpleHTTPServer 9090
And then simply hit http://{your system IP}:9090/
this works for me.
this worked for me,replacing your machine name with
http://localhost:x000
This worked for me on Windows 8. Did not download any software!
In cmd:
Go to the directory that your file is in.
python -m SimpleHTTPServer
Shows "Serving HTTP on 0.0.0.0 port 8000 ..."
Now, find out your system name. For Windows 8: Control Panel -> System. You will see the computer name here. Let's say it is "Abhinav".
Your local server will be hosted at "Abhinav.local:8000".
I followed the instructions here to run Django using the built-in webserver and was able to successfully run it using python manage.py runserver. If I access 127.0.0.1:port locally from the webserver, I get the Django page indicating it worked.
I realize the Django webserver is not a production server, but it's important for me for testing purposes to be able to access it from the outside world -- i.e. not from a web browser on the server, but from a different computer.
I tried:
http://mywebserver:port_django_runs_on
but it did not work. I also tried using the IP instead (based on ifconfig) to access:
http://myipaddress:port_django_runs_on
which did not work either.
The web server is running so it must be accessible from the outside, I'm just not sure how. I am running Linux with Apache, though I have not configured Django with Apache.
Any ideas on how to do this?
You have to run the development server such that it listens on the interface to your network.
E.g.
python manage.py runserver 0.0.0.0:8000
listens on every interface on port 8000.
It doesn't matter whether you access the webserver with the IP or the hostname. I guess you are still in your own LAN.
If you really want to access the server from outside, you also have to configure your router to forward port e.g. 8000 to your server.
Check your firewall on your server whether incoming connections to the port in use are allowed!
Assuming you can access your Apache server from the outside successfully, you can also try this:
Stop the Apache server, so that port 80 is free.
Start the development server with sudo python manage.py runserver 0.0.0.0:80
I had to add this line to settings.py in order to make it work (otherwise it showed an error when accessed from another computer)
ALLOWED_HOSTS = ['*']
then ran the server with:
python manage.py runserver 0.0.0.0:9595
Also ensure that the firewall allows connections to that port
Pick one or more from:
Your application isn't successfully listening on the intended IP:PORT
Because you haven't configured it successfully
Because the user doesn't have permission to
Your application is listening successfully on the intended IP:PORT, but clients can't reach it because
The server local iptables prevents it.
A firewall prevents it.
So, you can check that your application is listening successfully by running lsof -i as root on the machine and look for a python entry with the corresponding port you've specified.
Non-root users generally cannot bind to ports < 1024.
You'll need to look at iptables -nvL to see if there's a rule that would prevent access to the ip:port that you are trying to bind your application to.
If there is an upstream firewall and you don't know much about it, you'll need to talk to your network administrators.
just do this:
python manage.py runserver 0:8000
by the above command you are actually binding it to the external IP address.
so now when you access your IP address with the port number, you will be able to access it in the browser without any problem.
just type in the following in the browser address bar:
<your ip address>:8000
eg:
192.168.1.130:8000
you may have to edit the settings.py
add the following in the settings.py in the last line:
ALLOWED_HOSTS = ['*']
hope this will help...
For AWS users.
I had to use the following steps to get there.
1) Ensure that pip and django are installed at the sudo level
sudo apt-get install python-pip
sudo pip install django
2) Ensure that security group in-bound rules includ http on port 80 for 0.0.0.0/0
configured through AWS console
3) Add Public IP and DNS to ALLOWED_HOSTS
ALLOWED_HOSTS is a list object that you can find in settings.py
ALLOWED_HOSTS = ["75.254.65.19","ec2-54-528-27-21.compute-1.amazonaws.com"]
4) Launch development server with sudo on port 80
sudo python manage.py runserver 0:80
Site now available at either of the following (no need for :80 as that is default for http):
[Public DNS] i.e. ec2-54-528-27-21.compute-1.amazonaws.com
[Public IP] i.e 75.254.65.19
I'm going to add this here:
sudo python manage.py runserver 80
Go to your phone or computer and enter your computers internal IP (e.g 192.168.0.12) into the browser.
At this point you should be connected to the Django server.
This should also work without sudo:
python manage.py runserver 0.0.0.0:8000
UPDATED 2020
TRY THIS WAY
python manage.py runserver yourIp:8000
ALLOWED_HOSTS = ["*"]
You need just to allow any hosts :
settings.py :
ALLOWED_HOST = ['*']
Run your server :
python3 manage.py runserver 0.0.0.0:8000
If you want to connect android app just add internet permission in AndroidManifest
It's work for me ;)
open terminal
type : ifconfig
check results of ifconfig command
use the inet IP .. should look like this.. 192.168.1.121 or similar 192.168.x.x.
now runserver like you normally do but this time specify the inet IP
python3 manage.py runserver 192.168.x.x:8000 (replace the x with your inet)
also
on settings.py
ALLOWED_HOSTS = ['*']
install ngrok in terminal
sudo apt-get install -y ngrok-client
after that run:
ngrok http 8000
or
ngrok http example.com:9000
If you are using Docker you need to make sure ports are exposed as well