Can't access Django development server remotely [duplicate] - python

This question already has answers here:
Connecting to EC2 Django development Server
(6 answers)
Closed 6 years ago.
After reading this post on Stack Overflow, I cannot gain access to the files on my AWS EC2 Ubuntu instance by running the Django development server. Obviously this server would not be used in production but I want to use it for testing purposes and to check that my Django project is configured correctly.
I tried:
python manage.py runserver 0.0.0.0:8000
sudo python manage.py runserver 0.0.0.0:8000
python manage.py runserver 172.31.19.247:8000 (local IP for EC2 instance)
All of these run the development server in the console with no errors. The only problem is, I still can't access it!
How can I access my Django development server?
Ideally, I want to be able to access it through the public IP of the EC2 instance.

You need to make sure port 8000 is added as a Custom TCP Rule into your Security Group list of inbound ports.

Related

How to access flask application outside terminal? [duplicate]

This question already has answers here:
Configure Flask dev server to be visible across the network
(17 answers)
Closed 1 year ago.
I am trying to run simple hello world flask application. I followed all the steps mentioned here as I am using Ubuntu 18.04.5 LTS.
When I execute command flask run, I got following output:
But I am not able to get application run even after visiting the address http://10.142.0.2:5000. Tried using another IP address as well.
Opened port 5000, but not able to see in the list of open ports. Tried setting new firewall rule through GCP console as well.
If you are connecting via ssh you can use Gunicorn with nginx as a server. Note: They are running in the background(you can use the terminal when they are running.)
If you are trying to remove the port number you can change the port as 80
Are you trying to access your web app from another machine? That won't work because 127.0.0.1 means localhost. Try
flask run --host=0.0.0.0
This will tell flask to listen on all interfaces and not only the loopback address.
See https://flask.palletsprojects.com/en/latest/quickstart/#public-server for details.

How to run flask project in remote computer server? (windows) [duplicate]

This question already has answers here:
Are a WSGI server and HTTP server required to serve a Flask app?
(3 answers)
Closed 2 years ago.
I uploaded a Flask project that I prepared to a server of a windows computer. I can run the project over localhost on the computer I connect remotely. But I was asked to access the project from any computer with the IP and port address of the remote computer. What should I do for it?
You need to tell flask to run on all interfaces, either with:
flask run -h 0.0.0.0
Or if you're launching via app.run, provide the host argument:
if __name__ == '__main__':
app.run(host='0.0.0.0')
Of course if your machine has several interfaces, you could provide the IP of the specific interface instead of 0.0.0.0.
Bear in mind that the dev server is not meant for production. The above is fine if you want to access you're dev server remotely, but you'll probably want to run with something like gunicorn eventually, in which case provide the IP:port combo as the bind flag:
gunicorn --bind 0.0.0.0:5000 app:app

Accessing the Django embedded server for development inside PyCharm by other hosts inside my local network?

I'm working with PyCharm and I wonder if there's a way to make the Django embedded server accesible for the other hosts in my local network or I need to deploy my app on a dedicated web server such as Apache?
Now, I'm accessing my Django app like this in the browser:
http://localhost:8000/mypage/
and I want other users inside my local network to type:
http://my_private_ip:8000/mypage/
in their browsers and see the same page.
Just run the server (which is Django's embedded server FWIW, not PyCharm's) under http://my_private_ip:8000:
# ./manage.py help runserver
Usage: manage.py runserver [options] [optional port number, or ipaddr:port]
Starts a lightweight Web server for development.
(...)
# ./manage.py runserver my_private_ip:8000
Assuming a Unix environment.
You need to ensure the server is listening not on the lo interface but on all interfaces (or at least the one used to connect to the LAN).
If you can customize the way PyCharm launches the server, use 0.0.0.0 as the host, as in:
python manage.py runserver 0.0.0.0:8000
Your coworkers can then use your LAN IP address. If you don't know it, use $ ip a.

Run web server locally without exposing it publicly? [duplicate]

This question already has answers here:
How do you configure tomcat to bind to a single ip address (localhost) instead of all addresses?
(3 answers)
Closed 8 years ago.
I am running a dedicated server on Digital Ocean. My site uses Flask on NGINX through Gunicorn. During development I plopped a search engine (solr) on a local VM (through VMWare Fusion) which happens to be running Tomcat. It could have been running any web server per my question. In my app I make all search requests to that local ip: 192.168.1.5. Now, when I install Tomcat on my server and run it you can see it publicly at mysite.com:8080. There's the old welcome screen of Tomcat for the world to see. I want my app to be able to access it locally through localhost:8080 but not show it to the world. Is this possible?
The short answer is no.
While using a hosting plan, so actually anything that you are doing is 'exposed to the world' since you yourself have to access it remotely, like everyone else.
You have two options, the first, configure the Digital Ocean server to only accept connections from your public IP, and the second, keep using your development server locally until you are ready for primetime.

How do I access my django app running on Amazon ec2?

So, I have looked around stack overflow + other sites, but havent been able to solve this problem: hence posting this question!
I have recently started learning django... and am now trying to run it on ec2.
I have an ec2 instance of this format: ec2-xx-xxx-xx-xxx.us-west-2.compute.amazonaws.com on which I have a django app running. I changed the security group of this instance to allow http port 80 connections.
I did try to run it the django app the following ways: python manage.py runserver 0.0.0.0:8000 and python manage.py runserver ec2-xx-xxx-xx-xxx.us-west-2.compute.amazonaws.com:8000 and that doesnt seem to be helping either!
To make sure that there is nothing faulty from django's side, I opened another terminal window and ssh'ed into the instance and did a curl GET request to localhost:8000/admin which went through successfully.
Where am I going wrong? Will appreciate any help!
You are running the app on port 8000, when that port isn't open on the instance (you only opened port 80).
So either close port 80 and open port 8000 from the security group, or run your app on port 80.
Running any application on a port that is less than 1024 requires root privileges; so if you try to do python manage.py runserver 0.0.0.0:80 as a normal user, you'll get an error.
Instead of doing sudo python manage.py runserver 0.0.0.0:80, you have a few options:
Run a pre-configured AMI image for django (like this one from bitnami).
Configure a front end server to listen on port 80, and then proxy requests to your django application. The common stack here is nginx + gunicorn + supervisor, and this blog post explains how to set that up (along with a virtual environment which is always a good habit to get into).
Make sure to include your IPv4 Public IP address in the ALLOWED_HOSTS section in Django project/app/settings.py script...

Categories