I'm trying to implement SSL on my dev server, purely just so I can see it working.
I see from the Certbot page that Certbot works with Apache, Nginx, Haproxy and Plesk.
How would I go about implementing this with Django's dev server? I'm not working in a production environment of any kind yet.
Just to clear something up first: djangos dev server ./manage.py runserver does NOT serve HTTPS, only plain HTTP.
So you should use a webserver (from the ones you mentioned: Apache, Nginx, Haproxy or Plesk) to test you SSL/HTTPS with the certs.
See this post and this code example for ideas to implement SSL with the dev server.
You should create a self signed cert and then you can set up Nginx as a front facing webserver for your uWSGI Django app.
Related
I don't see this answered directly, so it's confusing. None of the tutorials I can find are using Nginx. They use Uvicorn instead for their examples. I have a running Nginx server hosting my React website. I want to add some data science endpoints using Python to enhance the React website. Can I run the endpoints in Nginx?
Actually NO, Nginx listen to your fastAPI application through gunicorn. So, you need to run gunicorn and bind it *.sock file, then Nginx listen to it.
Or you may read from official uvicorn doc, then you can try yourself
https://www.uvicorn.org/deployment/
Good Luck
I work on a python3.6 app that uses flask and oauth2client.
I want to serve https instead of http in gcloud environment.
I tried using talisman-flask:
https://github.com/GoogleCloudPlatform/flask-talisman
However, when I ran their sample app locally I got this error in my browser:
This site can’t provide a secure connection
127.0.0.1 sent an invalid response.
It works fine for http, but can't apparently serve https.
Are there some Talisman configurations I need to change?
Or maybe a whole different solution altogheter?
EDIT:
I changed from debug=True to debug=False and now I get automatically redirected to https but the above error message is still there.
One rather generic approach which can work even with the standard environment local development server (which doesn't support HTTPS) would be to use a reverse proxy.
Such solutions are documented in Appengine - Local dev server with https
It's an old thread, but if you want to serve HTTPS (with or without Talisman) you need, at least, a valid certificate. Please, create one at Let's Encrypt and install in your web server, even if your site are in the web or in your local environment. If you want a good tutorial to help further, I recommend this from Miguel Grinberg, a big "Flask Guru" ;-) .
I am using django rest framework.
Patch on api endpoint( users/user_id) is working in local django server on my machine. But on nginx development server its showing
{"detail":"Method \"METHOD_OTHER\" not allowed."}
Do we need to change some settings in nginx?
Ok I tried the access the same code from different network and it worked.
Probably it was firewall issue of that particular wifi network.
I created a Django Python application in localhost and setup virtualenv for running python application. I run this application from terminal and can access with this url- http://127.0.0.1:8000/ . On hosting time (server) how can i access this application using url?
I suggest you to check out this page of the django documentation if you haven't already: https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/
Deployment of a web application is not as easy as running the python development server, that is extremely simpler and is discouraged to be used on a server by the django documentation itself.
On a theoretic point of view, the reason why you can't access remotely the development server is because it binds the server on local only access: to make it accessible from an external computer you need to bind it to listen on 0.0.0.0 instead of 127.0.0.1, then you will be able to reach it on example.com:8000 depending on what the server's domain is and what port you choose. To use 0.0.0.0 you call manage.py runserver like this:
./manage.py runserver 0.0.0.0:8000
but avoid to do it, and opt for a more robust deployment :)
If your trying to deploy your application for the first time, and you want to get a feel of accessing your app from url, try heroku, https://www.heroku.com/
Easy and you don't have to worry about setting up everything.
Do i need to use NginX or am i able to host it without it?
I am developing my first django project and am at the point where i can run the app project using the command:
./manage.py run_gunicorn -c config/gunicorn
I can then view it going to:
http://127.0.0.1:8000/resources/
I would now like to try hosting it so that other PCs can access this.
Gunicorn is wsgi http server. It is best to use Gunicorn behind HTTP proxy server. We strongly advise you to use nginx.
# http://gunicorn.org/#deployment
Although there are many HTTP proxies available, we strongly advise that you use Nginx. If you choose another proxy server you need to make sure that it buffers slow clients when you use default Gunicorn workers. Without this buffering Gunicorn will be easily susceptible to denial-of-service attacks.
# http://docs.gunicorn.org/en/latest/deploy.html
Of course not. You can use lighttpd or any other web server that supports WSGI, SCGI, FastCGI or AJP. You may refer to this python documentation and django documentation, and these two questions on stackoverflow: Cleanest & Fastest server setup for Django, Differences and uses between WSGI, CGI, FastCGI, and mod_python in regards to Python? might be also helpful.
You don't need a frontend proxy; you can put a standalone webserver like gunicorn directly in production. But there are various reasons why you probably want to use a frontend webserver anyway.