the idea is that, say a developer has a set of tests to run against locahost:8000 and he has hardcoded that in his tests.
When we setup a proxy in a browser, the browser handles the proxy so that users only care about typing localhost:8000 instead of localhost:proxy_port. Browser actually sends request and receives response from the proxy port.
Can we simulate such so that the tests don't have to change to localhost:proxy_port (and the proxy server knows to route to port 8000). instead, the developer can continue to run as localhost:8000 in his tests, but when he's running his tests, the request automatically goes through the proxy server.
PS: Also without changing the port of the server. Since the assumption is that the port 8000 is running as application server and changing it to another port can break other things! So saying "change proxy server port to 8000 and my webapp server to 80001" doesn't solve the whole problem.
Set the HTTP_PROXY environment variable (and export it), and Python will honour that (as far as the standard library is used).
Related
I am working on a Django project where I am trying to use Jquery, I used a command-:
python -m HTTP.server on my Windows PowerShell, server is started but when I trying to use the address http://0.0.0.0:8000 in my browser it is showing an error as follow-
This site can’t be reached
The webpage at http://0.0.0.0:8000/ might be temporarily down or it may have moved permanently to a new web address.
ERR_ADDRESS_INVALID
my firewall is allowing access.
please help.
0.0.0.0 is not a real address; it's a special value that means "listen on every IPv4 network you can listen on".
To connect, you have to specify one of those addresses.
If your browser is on the same machine as the server, you want to use the localhost address, like either of the following:
http://localhost:8000
http://127.0.0.1:8000
That 127.0.0.1 is a real address, but it's a special one meaning "the same machine I'm on, without going through the network" (and localhost is a special name for that address).
If your server is on a different machine from the browser, you have to use an IP address or name that actually maps to the server. For example, if you started the server by doing ssh 192.168.1.100 and then running it in the shell there, you'll connect like this:
http://192.168.1.100:8000
Closing the django server (ctrl + c on termial) and then restarting my computer worked for me
I'm trying to connect to my website from another node on another network. If the nodes are in the same network, i can connect to the website without a problem.
I've forwarded port for ssh and Django (8000), I also have apache ready on port 9080.
ssh and apache ports work fine when connecting to them from external ip address, Django does not for some reason.
First, i tried to run the server on port 8000:
python manage.py runserver 0.0.0.0:8000
This works completely fine when connecting from the node that is in the same network as the server, but for some reason, whenever i try to access it from external ip address, the connection is refused.
To make sure it was Django, I also tried running the server on the same port as Apache (9080), although, i didn't expect "errorless" response, since i knew that port was occupied. But there was no change at all, I was still getting the same Apache page that i would get before.
I also tried allowing port 8000 on firewall:
sudo ufw allow 8000/tcp
But pretty sure this is not the problem, since this Debian came without any firewall.
I also tried to empty ALLOWED_HOSTS in settings, but there was no progression.
It seems like Django has no effect for external connections, what could be the reason?
I also struggle to understand the purpose of other http web server platforms in this case (e.g Apache, Nginx), Isn't Django creating a webserver itself along with its custom wsgi?
Firewall is not the problem, neither is the web server, then may the problem be caused by the Django itself? Maybe it is outer firewall?
It is not clear how you are configuring Apache to forward requests to Django, it seems like you are treating those as two independent components. If you want to use a web server in front of Django (recommended for production envs), you need to configure both Apache and Django.
Then, as you are running django in dev mode (python manage.py runserver 0.0.0.0:8000), you should reach Django in http://server_ip:8000 regardless of Apache, perhaps there is another firewall blocking the connection. Use tracert / traceroute to find out where the connection is blocked.
FInally, for production environments, it is recommended to use a web server in front of Django to increase security and performance. See the docs for further information.
My guess is that you have another firewall blocking the port. You opened the local firewall using ufw, but there may be an outer firewall.
python manage.py runserver 0.0.0.0:8000 starts correctly? If so, keep an eye in the log.
Inside the server, do a request wget http://localhost:8000. The request should be logged
If you can reach Apache in port 9080 from outside the server, you can:
Use nmap to find the opened / closed / filtered ports in the server to find if there is another firewall inbetween.
Configure Apache to forward requests to Django, although this does not solve the problem
In your question you say that you have forwarded port for ssh and Django. What exactly is this? Are you sure that you have not misconfigured your ssh server to listen in port 8000?
I want to make the development server in Django be on the internet while running Windows 10. How can I do this?
By the way, when I try to use my external IP, it doesn't work. It says that I can't use it
While starting the Django Server, mention the IP and PORT from which you want to accept the requests. Mention 0.0.0.0 to open it for all as:
python manage.py runserver 0.0.0.0:80
By default the Django's server accepts requests only via localhost.
Now make a request via using public IP of the system on which your Django's server is running
You can try a deployment on Heroku. Is relativelly easy to set up and provides you with a live server in minutes.
Sorry about the confusion, this is an old question but what actually happened was that I didn't add any port forwarding rules on my router. If I did, then the solutions raised by others would've worked. Since I didn't port forward, I just ended up hosting it on heroku.
I have a Django development server running on a remote centos VM on another lan. I have set up port forwarding using Secure CRT to access the web page through my browser from my desk pc. I am currently not using apache with the development server and is shutdown.
I start the server by running python manage.py runserver 0.0.0.0:80.
When I type either the ip or www.localhost.com into the web browser, my URL is read as if it has been doubled with the host being read as if it was also the path.
Page not found (404)##
Request Method: GET
Request URL: http://www.localhost.com/http://www.localhost.com/
When I try to access the development server from within the same LAN the page loads up fine.
I have been searching through the django documentation and stack overflow, but I have yet to find a similar problem to this. Does anyone have any thoughts on why this may be happening and what could be a possible solution?
Thank you very much in advance!
It looks like the request URL is incorrect:
http://www.localhost.com/http://www.localhost.com/ should probably be http://actual_machine_IP.com/
I'd start searching there. You won't be able to access the VM's port 80 from a different lan using localhost as the hostname since localhost is probably already set in your hosts file.
If you want to test your dev environ remotely, can I suggest either setting up Apache properly with port 80 (as opposed to using django's dev server--privilege restrictions and all that can be circumvented with sudo and other bad practice) or use a pre-built shared dev service like vagrant share.
I can't seem to figure this out. I created a new Ubuntu VM on Azure and I can SSH into it. I installed Node (which I've done many times) and I tried to run the test app from nodejs.org:
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');
However, when I go to the IP (which is the same one I SSHed into the box from) + :1337 it just never loads. I tried :80 too, but still no luck. I also tried running python -m SimpleHTTPServer on :8000 and I still can't view the site. I must be missing something.
Just so you know, I'm just trying to setup a simple dev box with a bunch of projects on it. I want to be able to work on my projects anywhere. Some are 100% front-end JS projects so SimpleHTTPServer would be fine. Some are Node projects too. In either case, I just want to be able to hit some port and see what I'm working on.
Oh also I opened up the Azure firewall to the VM, redirecting traffic from port 80 to port 1337 (https://www.evernote.com/shard/s5/sh/3aef8e76-04f6-48cb-84f9-32462bc425a7/f0cd749773a9d09cee66d00fe3e707c0)
You are listening loopback ip address. Try .listen(1337, '0.0.0.0'); to listen on all network interfaces
urgh azure. i cannot get port 80 open. is it the machine iptables?? some azure magical thing.
i know it cant be that hard.
unlike your view i do not see 'NONE' for load balancer. i see '--'/ whatever that means.