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.
Related
I am running python manage.py runserver from a machine A
when I am trying to check in machine B. The url I typed is http://A:8000/ .
I am getting an error like The system returned: (111) Connection refused
You can run it for machines in your network by
./manage.py runserver 0.0.0.0:8000
And than you will be able to reach you server from any machine in your network.
Just type on other machine in browser http://192.168.0.1:8000 where 192.168.0.1 is IP of you server... and it ready to go....
or in you case:
On machine A in command line ./manage.py runserver 0.0.0.0:8000
Than try in machine B in browser type http://A:8000
Make a sip of beer.
Source from django docs
You need to tell manage.py the local ip address and the port to bind to. Something like python manage.py runserver 192.168.23.12:8000. Then use that same ip and port from the other machine. You can read more about it here in the documentation.
I was struggling with the same problem and found one solution. I guess it can help you. when you run python manage.py runserver, it will take 127.0.0.1 as default ip address and 8000. 127.0.0.0 is the same as localhost which can be accessed locally. to access it from cross origin you need to run it on your system ip or 0.0.0.0. 0.0.0.0 can be accessed from any origin in the network.
for port number, you need to set inbound and outbound policy of your system if you want to use your own port number not the default one.
To do this you need to run server with command python manage.py runserver 0.0.0.0:<your port> as mentioned above
or, set a default ip and port in your python environment. For this see my answer on
django change default runserver port
Enjoy coding .....
Just in case any Windows users are having trouble, I thought I'd add my own experience. When running python manage.py runserver 0.0.0.0:8000, I could view urls using localhost:8000, but not my ip address 192.168.1.3:8000.
I ended up disabling ipv6 on my wireless adapter, and running ipconfig /renew. After this everything worked as expected.
in flask using flask.ext.script, you can do it like this:
python manage.py runserver -h 127.0.0.1 -p 8000
For people who are using CentOS7, In order to allow access to port 8000, you need to modify firewall rules in a new SSH connection:
sudo firewall-cmd --zone=public --permanent --add-port=8000/tcp
sudo firewall-cmd --reload
I had the same problem and here was my way to solve it:
First, You must know your IP address.
On my Windows PC, in the cmd windows i run ipconfig and select my IP V4 address. In my case 192.168.0.13
Second as mention above: runserver 192.168.0.13:8000
It worked for me.
The error i did to get the message was the use of the gateway address not my PC address.
First, change your directory:
cd your_project name
Then run:
python manage.py runserver
Ok just came across this post this is a little off topic but hopefully explains a few things, The IP 127.0.0.1 points to your network card so any traffic that you cause to go to that IP address will not leave your computer.
For example modern network cards in laptops for example will not even give you that IP if you are not connected to a wifi or cabled network so you'll need to be connected at least to activate the card.
If you need to run multiple servers on the same machine but want to access them with a domain then you have a couple of options
edit your computers host file to define the domain and what IP it goes to
use a DNS Alias I set up using a cname record years ago *.local.irishado.com will point to 127.0.0.1
so for example these three domains will point to your local machine
http://site1.local.irishado.com
http://site2.local.irishado.com
http://site3.local.irishado.com
will all point to your local machine then in python projects you will need to edit the projects setting file ALLOWED_HOSTS property to hold the domain it will accept
ALLOWED_HOSTS = ['site1.local.irishado.com']
I am running python manage.py runserver from a machine A
when I am trying to check in machine B. The url I typed is http://A:8000/ .
I am getting an error like The system returned: (111) Connection refused
You can run it for machines in your network by
./manage.py runserver 0.0.0.0:8000
And than you will be able to reach you server from any machine in your network.
Just type on other machine in browser http://192.168.0.1:8000 where 192.168.0.1 is IP of you server... and it ready to go....
or in you case:
On machine A in command line ./manage.py runserver 0.0.0.0:8000
Than try in machine B in browser type http://A:8000
Make a sip of beer.
Source from django docs
You need to tell manage.py the local ip address and the port to bind to. Something like python manage.py runserver 192.168.23.12:8000. Then use that same ip and port from the other machine. You can read more about it here in the documentation.
I was struggling with the same problem and found one solution. I guess it can help you. when you run python manage.py runserver, it will take 127.0.0.1 as default ip address and 8000. 127.0.0.0 is the same as localhost which can be accessed locally. to access it from cross origin you need to run it on your system ip or 0.0.0.0. 0.0.0.0 can be accessed from any origin in the network.
for port number, you need to set inbound and outbound policy of your system if you want to use your own port number not the default one.
To do this you need to run server with command python manage.py runserver 0.0.0.0:<your port> as mentioned above
or, set a default ip and port in your python environment. For this see my answer on
django change default runserver port
Enjoy coding .....
Just in case any Windows users are having trouble, I thought I'd add my own experience. When running python manage.py runserver 0.0.0.0:8000, I could view urls using localhost:8000, but not my ip address 192.168.1.3:8000.
I ended up disabling ipv6 on my wireless adapter, and running ipconfig /renew. After this everything worked as expected.
in flask using flask.ext.script, you can do it like this:
python manage.py runserver -h 127.0.0.1 -p 8000
For people who are using CentOS7, In order to allow access to port 8000, you need to modify firewall rules in a new SSH connection:
sudo firewall-cmd --zone=public --permanent --add-port=8000/tcp
sudo firewall-cmd --reload
I had the same problem and here was my way to solve it:
First, You must know your IP address.
On my Windows PC, in the cmd windows i run ipconfig and select my IP V4 address. In my case 192.168.0.13
Second as mention above: runserver 192.168.0.13:8000
It worked for me.
The error i did to get the message was the use of the gateway address not my PC address.
First, change your directory:
cd your_project name
Then run:
python manage.py runserver
Ok just came across this post this is a little off topic but hopefully explains a few things, The IP 127.0.0.1 points to your network card so any traffic that you cause to go to that IP address will not leave your computer.
For example modern network cards in laptops for example will not even give you that IP if you are not connected to a wifi or cabled network so you'll need to be connected at least to activate the card.
If you need to run multiple servers on the same machine but want to access them with a domain then you have a couple of options
edit your computers host file to define the domain and what IP it goes to
use a DNS Alias I set up using a cname record years ago *.local.irishado.com will point to 127.0.0.1
so for example these three domains will point to your local machine
http://site1.local.irishado.com
http://site2.local.irishado.com
http://site3.local.irishado.com
will all point to your local machine then in python projects you will need to edit the projects setting file ALLOWED_HOSTS property to hold the domain it will accept
ALLOWED_HOSTS = ['site1.local.irishado.com']
Looking for advice on how I can run celery pdb inside my docker container while port forwarding so i can access from the outside world.
I am following the guide at http://celery.readthedocs.org/en/latest/tutorials/debugging.html
The issue I am facing is that even when I tell the container.
-e CELERY_RDB_HOST='0.0.0.0' -e CELERY_RDB_PORT='6900' -p 6900:6900.
And get to the breakpoint in the app, the port that actually gets open is not what I asked for so my port forward no longer is valid.... Eg. the port 6902 gets opened instead, and no matter what I ask the port to be, it changes again to not what I asked for.
I know it chooses from a list of 100 ports that it deems 'available' but not sure how to get around this problem. Any advise would be welcome.
Thanks!
You can run your container by specifying a range of ports (see http://docs.docker.com/reference/run/#expose-incoming-ports):
docker run -d -e CELERY_RDB_HOST='0.0.0.0' -p 6900-7000:6900-7000 celery
After that, when you hit your breakpoint, you just need to telnet into it:
telnet localhost 6902
I've got the same issue, celery v4.4.7 in 11-2020.
Whatever I set to enviroment variable CELERY_RDB_PORT, I'll always get that nuber +2.
IE. If I set 9024, then rdb will listen on 9026.
Your docker command might look like this.
CELERY_RDB_HOST='0.0.0.0' -e CELERY_RDB_PORT='6900' -p 6902:6902
It's probably celery's bug.
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.
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".