nginx使用ssl模块配置HTTPS支持,
默认情况下ssl模块并未被安装,如果要使用该模块则需要在编译时指定–with-http_ssl_module参数,安装模块依赖于OpenSSL库和一些引用文件,通常这些文件并不在同一个软件包中。通常这个文件名类似libssl-dev。
生成证书
可以通过以下步骤生成一个简单的证书:
首先,进入你想创建证书和私钥的目录,例如:
- $ cd /usr/local/nginx/conf
创建服务器私钥,命令会让你输入一个口令:
- $ openssl genrsa -des3 -out server.key 1024
创建签名请求的证书(CSR):
- $ openssl req -new -key server.key -out server.csr
在加载SSL支持的Nginx并使用上述私钥时除去必须的口令:
- $ cp server.key server.key.org
- $ openssl rsa -in server.key.org -out server.key
配置nginx
最后标记证书使用上述私钥和CSR:
- $ openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
修改Nginx配置文件,让其包含新标记的证书和私钥:
- server {
- server_name YOUR_DOMAINNAME_HERE;
- listen 443;
- ssl on;
- ssl_certificate /usr/local/nginx/conf/server.crt;
- ssl_certificate_key /usr/local/nginx/conf/server.key;
- }
重启nginx。
这样就可以通过以下方式访问:
https://YOUR_DOMAINNAME_HERE
另外还可以加入如下代码实现80端口重定向到443IT人乐园
- server {
- listen 80;
- server_name ww.centos.bz;
- rewrite ^(.*) https://$server_name$1 permanent;
- }
转载请注明文章来源:http://www.centos.bz/2011/12/nginx-ssl-https-support/

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Linux new version
SublimeText3 Linux latest version

Atom editor mac version download
The most popular open source editor

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Mac version
God-level code editing software (SublimeText3)