[Nginx, Django]Securing connections with SSL
来源:互联网 发布:蓝点网络 编辑:程序博客网 时间:2024/04/28 11:39
Reference: Django by Example Chapter 13
Create directory under /etc/nginx
, and cd
to that directory
mkdir /etc/nginx/sslcd /etc/nginx/ssl
Creating a SSL certificate
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout your_key_name.key -out your_cert_name.crt
You will be asked to enter the following information:
Country Name (2 letter code) []:State or Province Name (full name) []:Locality Name (eg, city) []: Organization Name (eg, company) []:Organizational Unit Name (eg, section) []:Common Name (e.g. server FQDN or YOUR name) []: Email Address []:
The most important field is the Common Name
. You have to specify the domain name for the certificate, it must match the way you access your website.
If you access your website by IP, eg. 10.0.0.1, fill in 10.0.0.1
If you access your website by Domain Name, eg. example.cm, fill in example.com
Configuring Nginx to use SSL
Edit the nginx.conf
file or the file in your sites-enabled
directory and modify the server directive to include the following
SSL directives:
server { listen 80; listen 443 ssl; ssl_certificate /etc/nginx/ssl/your_cert_name.crt; ssl_certificate_key /etc/nginx/ssl/your_key_name.key; server_name ip_or_domain_name; # ...}
Restart Nginx with the following command:
systemctl restart nginx
Configuring your project for SSL
Django includes some settings specific to SSL. Edit the settings.py
and add the following code to it:
SECURE_SSL_REDIRECT = TrueCSRF_COOKIE_SECURE = True
These settings are as follows:
• SECURE_SSL_REDIRECT
: Whether HTTP requests have to be redirected to
HTTPS ones
• CSRF_COOKIE_SECURE
: This has to be set to establish a secure cookie for the
cross-site request forgery protection
- [Nginx, Django]Securing connections with SSL
- Securing Windows Azure with SSL
- Securing Communications with SSL/TLS: A High-Level Overview
- Securing Development with PMD
- Securing WCF Services with Certificates
- deploy django with url prefix in nginx
- SSL & TLS Essentials: Securing the Web
- django ssl
- nginx connections 介绍
- porting nginx to android with ssl module(移植nginx及其ssl模块到android设备)
- Securing Sockets with OpenSSL By Sean Walton
- Securing REST APIs With Spring Boot
- Setting up Django with Nginx, Gunicorn, virtualenv, supervisor and PostgreSQL
- nginx ssl
- Nginx ssl
- Nginx源码分析-connections数组
- Nginx源码分析-connections数组
- Nginx源码分析-connections数组
- 深度学习(六)caffe入门学习
- MFC使用WM_HOTKEY添加快捷键
- 实现图片Bitmap简单编辑的三种方式
- JNI:Java Native Interface
- 纹理CCTexture2D和精灵CCSprite
- [Nginx, Django]Securing connections with SSL
- artemplate的自动保存问题
- 深度学习(七)caffe源码c++学习笔记
- 不必成为什么
- linux bind()遇到Address already in use问题
- hdu 3084 How Many Answers Are Wrong【带权并查集】
- Android LayoutInflater详解
- RHCE 学习笔记(16) - KickStart
- HTML代码转换编辑器