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

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.

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

how can I post to api running on remote desktop?

I'm creating a python flask api on remote desktop and running it on localhost of remote desktop.
Is there anyway I can access this api from my local machine?
We are working in a team and I want to share this with my team members, but this is confidential and not to be deployed on open server.
We want to post and get the result with every member's local machine from api runnnig on remote desktop.
Both of our local machines and remote desktop are windows10.
Sorry for being abstract but I'm searching for any way out. Thanks.
Well, you should open your way to this API. You'll have to set up a VPN or IP address filter in the server so you can access the server from your network while still have it secured on the Internet. You can also setup a simpler proxy if you prefer it. I'll not cover the details on how to setup a VPN or proxy since it can get pretty extensive, but a Google search will help you out find the best alternative for you.
AFAIK, the Remote Desktop Protocol does not allow for any kind of VPN. However, if you can switch to TeamViewer, it does have an easy to setup VPN system that will allow you to get into the network with few configuration. Once a VPN is configured, it will work like if you were in the same network as the server, so from there you can access your API from your host machine by just going to the IP address of the server.
Do notice the security policies of whoever owns the server, since you can get into trouble if you don't have permission to enable some access from the outside. Security goes always in front of comfort.
Short term solution:
Firstly download ngrok for your operating system.
For debugging and testing purposes you can expose a secure tunnel connection to your API by running this command in your command prompt / terminal.
ngrok http <PORT_NUMBER>-host-header="localhost:<PORT_NUMBER>"
Where PORT_NUMBER is the port number in which your flask application is running.
Example if your flask application is running at port 5000 then simply execute this command:
ngrok http 5000 -host-header="localhost:5000"
Running this will give you two hostnames one with HTTP and other a secure HTTPS connected by a tunnel like this for a duration of 8 hours after which the command needs to again re-run.
Which you can call remotely
Long term solution:
Deploy flask application using FastCGI
or
To a cloud infrastructure provider like Microsoft Azure which gives readymade templates for flask applications.

Error accessing my webpage from network

I've just started learning network developing using Flask. According to its official tutorial:
Externally Visible Server
If you run the server you will notice that the server is only
accessible from your own computer, not from any other in the network.
This is the default because in debugging mode a user of the
application can execute arbitrary Python code on your computer.
If you have the debugger disabled or trust the users on your network,
you can make the server publicly available simply by adding
--host=0.0.0.0 to the command line:
flask run --host=0.0.0.0
This tells your operating system to listen on all public IPs.
However, when I try to access 0.0.0.0:5000 on another device, I got an error: ERR_CONNECTION_REFUSE. In fact, I think this behavior is reasonable, since people all around world can use 0.0.0.0:5000 for different testing purposes, but isn't the tutorial implying that adding --host=0.0.0.0 can make my webpage "accessible not only from your own computer, but also from any other in the network"?
So, my question is:
What does adding --host=0.0.0.0 do?
How can I access my webpage on device B while the server is running on device A?
You don't access the Flask server on another computer by going to 0.0.0.0:5000. Instead, you need to put in the IP address of the computer that it is running on.
For example, if you are developing on a computer that has IP address 10.10.0.1, you can run the server like so:
flask run --host=0.0.0.0 --port=5000
This will start the server (on 10.10.0.1:5000) and listen for any connections from anywhere. Now your other device (say, on 10.10.0.2) can access that server by going to http://10.10.0.1:5000 in the browser.
If you don't have the host=0.0.0.0, the server on 10.10.0.1 will only listen for connections from itself (localhost). By adding that parameter, you are telling it to listen from connections external to itself.

Can't access Django development server remotely [duplicate]

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.

Categories