Nginx - Additional Modules, SSL and Security
Nginx provides secure HTTP functionalities through the SSL module but also offers an extra module called Secure Link that helps you protect your website and visitors in a totally different way.
SSL
The SSL module enables HTTPS support, HTTP over SSL/TLS in particular. It gives you the possibility to serve secure websites by providing a certificate, a certificate key, and other parameters defined with the following directives:
This module is not included in the default Nginx build.
ssl
Context: http, server
Enables HTTPS for the specified server. This directive is the equivalent of listen 443 ssl or listen port ssl more generally.
Syntax: on or off
Default: ssl off;
ssl_certificate
Context: http, server
Sets the path of the PEM certificate.
Syntax: File path
ssl_certificate_key
Context: http, server
Sets the path of the PEM secret key file.
Syntax: File path
ssl_client_certificate
Context: http, server
Sets the path of the client PEM certificate.
Syntax: File path
ssl_crl
Context: http, server
Orders Nginx to load a CRL (Certificate Revocation List) file, which allows checking the revocation status of certificates.
ssl_dhparam
Context: http, server
Sets the path of the Diffie-Hellman parameters file.
Syntax: File path.
ssl_protocols
Context: http, server
Specifies the protocol that should be employed.
Syntax: ssl_protocols [SSLv2] [SSLv3] [TLSv1] [TLSv1.1] [TLSv1.2];
Default: ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_ciphers
Context: http, server
Specifies the ciphers that should be employed. The list of available ciphers can be obtained running the following command from the shell: openssl ciphers.
Syntax: ssl_ciphers cipher1[:cipher2…];
Default: ssl_ciphers ALL:!ADH:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
ssl_prefer_server_ciphers
Context: http, server
Specifies whether server ciphers should be preferred over client ciphers.
Syntax: on or off
Default: off
ssl_verify_client
Context: http, server
Enables verifying certificates transmitted by the client and sets the result in the $ssl_client_verify. The optional_no_ca value verifies the certificate if there is one, but does not require it to be signed by a trusted CA certificate.
Syntax: on | off | optional | optional_no_ca
Default: off
ssl_session_cache
Context: http, server
Configures the cache for SSL sessions.
Syntax: off, none, builtin:size or shared:name:size
Default: off (disables SSL sessions)
ssl_session_timeout
Context: http, server
When SSL sessions are enabled, this directive defines the timeout for using session data.
Syntax: Time value
Default: 5 minutes
Additionally, the following variables are made available:
- $ssl_cipher: Indicates the cipher used for the current request
- $ssl_client_serial: Indicates the serial number of the client certificate
- $ssl_client_s_dn and $ssl_client_i_dn: Indicates the value of the Subject and Issuer DN of the client certificate
- $ssl_protocol: Indicates the protocol at use for the current request
- $ssl_client_cert and $ssl_client_raw_cert: Returns client certificate data, which is raw data for the second variable
- $ssl_client_verify: Set to SUCCESS if the client certificate was successfully verified
- $ssl_session_id: Allows you to retrieve the ID of an SSL session
Setting Up an SSL Certificate
Although the SSL module offers a lot of possibilities, in most cases only a couple of directives are actually useful for setting up a secure website. This guide will help you configure Nginx to use an SSL certificate for your website (in the example, your website is identified by secure.website.com). Before doing so, ensure that you already have the following elements at your disposal:
- A .key file generated with the following command: openssl genrsa -out secure.website.com.key 1024 (other encryption levels work too).
- A .csr file generated with the following command: openssl req -new -key secure.website.com.key -out secure.website.com.csr.
- Your website certificate file, as issued by the Certificate Authority, for example, secure.website.com.crt. (Note: In order to obtain a certificate from the CA, you will need to provide your .csr file.)
- The CA certificate file as issued by the CA (for example, gd_bundle.crt if you purchased your certificate from GoDaddy.com).
The first step is to merge your website certificate and the CA certificate together with the following command:
cat secure.website.com.crt gd_bundle.crt > combined.crt
You are then ready to configure Nginx to serve secure content:
server {
listen 443;
server_name secure.website.com;
ssl on;
ssl_certificate /path/to/combined.crt;
ssl_certificate_key /path/to/secure.website.com.key;
[…]
}
Secure Link
Totally independent from the SSL module, Secure link provides a basic protection by checking the presence of a specific hash in the URL before allowing the user to access a resource:
location /downloads/ {
secure_link_md5 "secret";
secure_link $arg_hash,$arg_expires;
if ($secure_link = "") {
return 403;
}
}
With such a configuration, documents in the /downloads/ folder must be accessed via a URL containing a query string parameter hash=XXX (note the $arg_hash in the example), where XXX is the MD5 hash of the secret you defined through the secure_link_md5 directive. The second argument of the secure_link directive is a UNIX timestamp defining the expiration date. The $secure_link variable is empty if the URI does not contain the proper hash or if the date has expired. Otherwise, it is set to 1.
This module is not included in the default Nginx build.
Nginx - Additional Modules, SSL and Security的更多相关文章
- Nginx - Additional Modules, About Your Visitors
The following set of modules provides extra functionality that will help you find out more informati ...
- Nginx - Additional Modules, Website Access and Logging
The following set of modules allows you to configure how visitors access your website and the way yo ...
- Nginx - Additional Modules, Limits and Restrictions
The following modules allow you to regulate access to the documents of your websites — require users ...
- Nginx - Additional Modules, Content and Encoding
The following set of modules provides functionalities having an effect on the contents served to the ...
- Nginx自建SSL证书部署HTTPS网站
一.创建SSL相关证书 1.安装Nginx(这里为了测试使用yum安装,实际看具体情况) [root@localhost ~]# yum install nginx -y #默认yum安装已经支持SS ...
- Nginx 下配置SSL证书的方法
1.Nginx 配置 ssl 模块 默认 Nginx 是没有 ssl 模块的,而我的 VPS 默认装的是 Nginx 0.7.63 ,顺带把 Nginx 升级到 0.7.64 并且 配置 ssl 模块 ...
- Nginx配置免费SSL证书StartSSL,解决Firefox不信任问题
先在StartSSL上申请免费一年的SSL证书,具体过程网上很多教程.然后把申请到的key和crt文件上传到服务器,比如/usr/local/nginx/certs/. Nginx配置SSL证书 直接 ...
- CentOS6.5 下在Nginx中添加SSL证书以支持HTTPS协议访问
参考文献: 1. NginxV1.8.0安装与配置 2. CentOS下在Nginx中添加SSL证书以支持HTTPS协议访问 3. nginx配置ssl证书的方法 4.nginx强制使用https访问 ...
- nginx: [emerg] the "ssl" parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.conf:37
一:开始Nginx的SSL模块 1.1 Nginx如果未开启SSL模块,配置Https时提示错误 1 nginx: [emerg] the "ssl" parameter requ ...
随机推荐
- uva10474 简单排序查找 一次AC
题目很简单,加上读题20分钟一次AC.还是用到了快排qsort. #include<iostream> #include<cstdlib> using namespace st ...
- POJ1228(稳定凸包问题)
题目:Grandpa's Estate 题意:输入一个凸包上的点(没有凸包内部的点,要么是凸包顶点,要么是凸包边上的点),判断这个凸包是否稳定.所谓稳 定就是判断能不能在原有凸包上加点,得到一个更 ...
- C++中void型指针
问题由来: PX_FORCE_INLINE void* operator new(size_t size, const char* handle, const char * filename, int ...
- opennebula 编译日志
[root@localhost opennebula-]# scons mysql=yes scons: Reading SConscript files ... Testing recipe: xm ...
- CSS3教程:Transform的perspective属性设置
1 2 <div id="animateTest" style="-webkit-transform: perspective(400px) rotateY(4 ...
- 脚本命令高级Bash脚本编程指南(31):数学计算命令
题记:写这篇博客要主是加深自己对脚本命令的认识和总结实现算法时的一些验经和训教,如果有错误请指出,万分感谢. 高等Bash脚本编程指南(31):数学盘算命令 成于坚持,败于止步 操作数字 factor ...
- android 手电筒的实现
android手机用闪光灯做成手电筒的应用非常多,可是有的不能用. 后来发现是除了把 camera device的 flashmode设置成torch外还要打开预览: 以下是代码: MainActiv ...
- 让WPS支持VHDL的关键词加粗
WPS的VBA在这里下载:http://bbs.wps.cn/forum.php?mod=viewthread&tid=22347925 语法高亮是参考Word的,这篇文章:http://bl ...
- Swift学习笔记四
前面三篇笔记通过一些示例展示了Swift的一些特性,粗略地介绍了它的语法和特色,从这一篇笔记开始,将正式系统地介绍Swift的语法和特性了. Swift是一门为iOS和OSX开发准备的全新语言,但是它 ...
- Amazon DynamoDB 概览
1. 什么是Amazon DynamoDB DynamoDB 是一种快速.全面受管的 NoSQL 数据库服务,它能让用户以简单并且经济有效地方式存储和检索任何数据量,同时服务于任何程度的请求流量.所有 ...