Django runserver shows HTTP - django

I have configured nginx to run HTTPS. I also rewrite all the rules so it's running under HTTPS.
But is it true that Django still runs with HTTP internally?
Django version 1.2.1, using settings 'myproject.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[14/Aug/2012 23:57:04] "GET /app/c HTTP/1.0" 200 4
[14/Aug/2012 23:57:09] "GET /app/c HTTP/1.0" 200 4
Yes. I know my version is way way way outdated.
I checked request.is_secure and it returns True as I am accessing HTTPS.

Correct, internally you will use http to communicate through your proxy server but all your external traffic will use the https method.
To further secure your traffic ensure that you only bind to a local address, or alternatively use a socket to connect between nginx and your application server.
I do hope that you're not using django's development server in production, you should instead use something like gunicorn as your application server.

Related

Remove port from URL - Django Apache2 Gunicorn

I would like to know how to omit the port number from my URL.
I currently host a website on an Apache Ubuntu server on port 443 and redirect any http traffic to the https version of the site.
(www.mycompany.com)
However, I also run a Django server on the same Apache VPS using Gunicorn, currently on port 8000 and would like to achieve the URL of www.mycompany.com/blog
My current situation for the URL is www.mycompany.com:8000/blog
I have tried altering the ports that the Django server runs on to 443 and 80, but quickly realised the firewall won't allow that.
I am not sure what to do. Do I have to do a reverse proxy?

How do i run django application without port number

How do i run django application without port number: i had tried Django: Run django app on server without port? but didn't work.
Web services must bind a port on a interface of the system. So, you should specify a port number to run your Django application. The default port number for HTTP is 80, for HTTPS 443. But you can use a custom port between [1-65535]:
For example;
python manage.py runserver 7000
You may try the following:
python manage.py runserver 80
or if you don't have permissions (assuming you are using Linux):
sudo python manage.py runserver 80
Then, you can access your application: http://localhost/
In general, web services need a port to run. If the port used is default http (80) or https (443) port, modern web browsers hide it from seeing in the address bar.
In a development server, you can hide the port(because you don't want to see it anymore) by assigning it to port 80 if it is not used by any other web service in the system(otherwise django will complain):
python manage.py runserver 80
In a production server, you need to use servers like Gunicorn to run your django app in the backend and a web server like Nginx or Apache to serve your backend to external world. In that case, since web servers use http/https ports, no ports will be visible in the browser.

This site can't provide a secure connection ERR_SLL_PROTOCOL ERROR

I have a google appengine project running in localhost. Everything works fine until i go to the 'login' page. When i go there i get the following error:
This site can’t provide a secure connection 127.0.0.1 sent an invalid response.
Try running Windows Network Diagnostics.
ERR_SSL_PROTOCOL_ERROR
the appengine command i use to run the project is dev_appserver.py" --host 127.0.0.1 . This is run pycharm. This only occurs in the 'login' endpoint and no other endpoint.
The console error i get is:
default: "GET /signin HTTP/1.1" 301 -
to connect over HTTPS you need a valid SSL certificate on your server here is you local server as I understand from the message. you can get a certificate for your local server but I don't think it's worth the trouble while working locally. On the other hand when you deploy to Google App Engine, you get SSL certificate automatically and it's managed by Google, that's why your code works without any problem in the deployment.

How to server HTTP/2 Protocol with django

I am planing to deploy my Django application with HTTP/2 protocol but I'm unable to find the proper solution. How can I serve my Django web application with HTTP/2, the only thing that I find is hyper-h2.
I read the documentation but unable to setup the connections.
You can do with Nginx proxy
if you have existing nginx config. you do by just adding a word .http2 in listen
listen 443 ssl http2 default_server;
full document avaliable in
https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-with-http-2-support-on-ubuntu-16-04
One option is to use Apache httpd server with mod_wsgi. Apache supports terminating HTTP/2. The link to your Django application is still via WSGI API so you don't really get any access to HTTP/2 specific features in your application. You can though configure Apache to do things like server push on your behalf.
https://httpd.apache.org/docs/2.4/howto/http2.html
https://httpd.apache.org/docs/2.4/mod/mod_http2.html
To support HTTP 2.0, You can deploy Django apps on web servers like Daphne using ASGI (which is the spiritual successor to WSGI).
you can read more about deploying Django with ASGI in the official documentaion
to read more about ASGI and what is it, introduction to ASGI
to read more about Daphne server, official repository

My ngrok Tunne Status shows reconnecting running on a custom port (4901)

I am running a ngrok on 4901 port.
I am also running a flask webserver on the same port. The idea is that I want to access my local webserver from outside world to do some app testing.
What am I missing ?
NGROK running on 4901
./ngrok 4901
ngrok
Tunnel Status reconnecting Version
1.7/ Web Interface 127.0.0.1:4040
# Conn 0 Avg Conn Time 0.00ms
FLASK:
python webserver.py
* Running on http://0.0.0.0:4901/
127.0.0.1 - - [01/Jul/2016 15:16:02] "GET / HTTP/1.1" 200 -
You are using ngrok version 1.7, which has now been shut down completely. Quoting from their announcement:
As of April 4, 2016, all 1.X sessions were no longer be and service ended completely.
You should be able to upgrade to version 2.0+ and keep using it, although I haven't tried it yet myself.