How do I point my reserved domain to a Django EC2 instance? - python

Ok so I'm hosting a Django EC2 instance right now using ngrok http 8000 and leaving it running. It's doing fine but a lot of browsers are blocking the traffic to my site. I need to make my reserved domain (I have some on Amazon and some on 1 and 1) to my 123.4.5.67:8000 public IPv4 IP or just my public IPv4 DNS on my EC2.
What I need in a nutshell is example.com to redirect to 123.4.5.67:8000 while still saying example.com in the url.
So far I have heard of Apache, WSGI, and nginx. None of them have worked for me, but maybe I haven't gotten the right direction.
Please help!

I’m pretty sure that you need to make this change wherever you host your domain. The only way i was able to do this with my personal server was to point to port 80instead of 8000

Related

How to expose Docker terminal to the internet?

I am creating an online IDE for different languages. So my approach to the same is to spin up a docker container from my DJango app once a user runs his code, but the problem is how do I expose the terminal of the docker container to the internet and make it accessible via the browser? I am planning to use xterm.js for the frontend of the terminal but am unable to connect to it.
Any form of insight is appreciable.
You can you an reverse-proxy with NGINX to point to your localIP:<container_port>, and then modify with your domain name.
As this exemple below:
location /some/path/ {
proxy_pass http://www.example.com/link/;
}
Adding some links to help you.
enter link description here
Also you can use 'Nginx Proxy Manager'
Short answer:
Your application uses a port to access it (for example, you use 127.0.0.1:8080 or 192.168.1.100:3000).
127.0.0.1 means the computer you are using right now, 192.168.1.100 is a computer inside the 192.168.1.0 network. (Your LAN)
You must create (on your router) access from the internet to your application.
For exemple, if your public IP address is 123.245.123.245, you need to use an external port (ex: 80), and map it to your internal address and port (ex: 192.168.1.100:3000)
the URL 123.245.123.245:80 will redirect to the website on 192.168.1.100:3000.
On the short term, this is the easiest solution.
For the long term, you should try using a Reverse Proxy.
It's a program that will (depending on the domain) redirect to sites inside your network and adding encryption in the requests (if possible).
Check this link : doc

Locally hosted Django project for long-term use in local network

I am currently implementing a Django web application, which will be used only locally but long-term. I already managed to start the Django server on my local machine using python manage 0.0.0.0:myport and I am able to connect from any mobile device using MyLocalIPv4:myport.
In best case I only want to start the Django server once, establish a connection between a mobile device and the web app and let the web app run for an undefined long time on that mobile device
Now my assumption is, that MyLocalIPv4 will be changing over time as it is a dynamic IP address, which will force the user (or even worse myself) to look up the new IP address and re-establish the connection.
My question are: Do you know any mechanisms on how I can avoid this type of behaviour using another (maybe static) referral to the web app ? What do you think about this web application in term of security issues ?
DNS is the way to go. What you want is a (internal) domain that would map to your computer IP address.
There are many ways you can achieve that but I suggest going with whatever tools you have available. I assume that for your home network you're using some sort of a consumer-grade home router with wireless access point. Very often this type of hardware offers some way to "map" the hostname of a machine to its internal-network IP address.
For example, at home I'm using a RT-AC1200G+ router, which runs an internal DNS server and maps hostnames of clients of my network to their IP:
$ dig +short #192.168.1.2 samu-pc
192.168.1.70
$ ifconfig |grep 192.168.1.70
inet 192.168.1.70 netmask 255.255.255.0 broadcast 192.168.1.255
Alternatively, one of the easier solutions would be to ensure your IP does not change. You could assign a static IP to your django-server machine, OR if you want to continue using DHCP - use your routers functions to make a static assignment to a specific, static IP address using your network card's MAC address.
Disclaimer: There are other, more "professional" ways of solving service discovery within a network, but I would consider them overkill to your home network setup. Also, if you care about security, you should consider running the django app behind a reverse proxy with HTTPs on the front, just to ensure nobody in your internal network is trying to do something nasty.

Access django main page by its name not ip

is there a way to configure a Django server in that way so I can open my local webpage by typing 'weatherstation.local' and not by the IP:port?
in your router you might be able to set DNS. if DNS administration exists, then here you can set different domain names for IP addresses on your network.
You can give your ip address multiple domain names, and then you can use somthing like NGINX to route the domain calls to different services that you are running on your server.
Good luck, I hope this was helpful ;-)

How to make django server public in rasb?

I use django server. First, I do port forwarding my raspberrypi ( my public ip : 12345) using my Sharer.
So, I can access my raspberrypi server using x-shell(putty) and then I want to access my dajngo web server. In my home I can access my django server (192.168.1.11:8000)
But I can't access my django server except my home wifi-zone.
I think i have to do port forwarding one more, but I'm not sure. Then, what can i do?
Are you asking to host a webserver/django app from your home network, to the public internet?
If so, I do not have the technical detail on how to accomplish that - but from a security perspective that is not a great idea. You might want to look into some of the free/cheap hosts out there that support python and django

Django runserver bound to 0.0.0.0, how can I get which IP took the request?

I'm running a temporary Django app on a host that has lots of IP addresses. When using manage.py runserver 0.0.0.0:5000, how can the code see which of the many IP addresses of the machine was the one actually hit by the request, if this is even possible?
Or to put it another way:
My host has IP addresses 10.0.0.1 and 10.0.0.2. When runserver is listening on 0.0.0.0, how can my application know whether the user hit http://10.0.0.1/app/path/etc or http://10.0.0.2/app/path/etc?
I understand that if I was doing it with Apache I could use the Apache environment variables like SERVER_ADDR, but I'm not using Apache.
Any thoughts?
EDIT
More information:
I'm testing a load balancer using a small Django app. This app is listening on a number of different IPs and I need to know which IP address is hit for a request coming through the load balancer, so I can ensure it is balancing properly.
I cannot use request.get_host() or the request.META options, as they return what the user typed to hit the load balancer.
For example: the user hits http://10.10.10.10/foo and that will forward the request to either http://10.0.0.1/foo or http://10.0.0.2/foo - but request.get_host() will return 10.10.10.10, not the actual IPs the server is listening on.
Thanks,
Ben
request.get_host()
https://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpRequest.get_host
but be aware this can be cheated so don't relay your security on it.
If users are seeing your machine under same address I am not sure if this is possible via runserver (it is supposed to be simple development tool).
Maybe you could use nginx?
Or if this is only for testing do something like:
for i in 1 2 3 4 5; do manage.py runserver 10.0.0.$i:5000; done
and then sys.args[2] is your address
If your goal is to ensure the load balancer is working correctly, I suppose it's not an absolute requirement to do this in the application code. You can use a network packet analyzer that can listen on a specific interface (say, tcpdump -i <interface>) and look at the output.

Categories