search
Homephp教程php手册nginx使用ssl模块配置HTTPS支持,

nginx使用ssl模块配置HTTPS支持,

Jun 13, 2016 am 08:49 AM
httpsnginxsslusesupportmoduleConfigurationdefault

nginx使用ssl模块配置HTTPS支持,

默认情况下ssl模块并未被安装,如果要使用该模块则需要在编译时指定–with-http_ssl_module参数,安装模块依赖于OpenSSL库和一些引用文件,通常这些文件并不在同一个软件包中。通常这个文件名类似libssl-dev。

生成证书

可以通过以下步骤生成一个简单的证书:
首先,进入你想创建证书和私钥的目录,例如:

  1. $ cd /usr/local/nginx/conf

创建服务器私钥,命令会让你输入一个口令:

  1. $ openssl genrsa -des3 -out server.key 1024

创建签名请求的证书(CSR):

  1. $ openssl req -new -key server.key -out server.csr

在加载SSL支持的Nginx并使用上述私钥时除去必须的口令:

  1. $ cp server.key server.key.org
  2. $ openssl rsa -in server.key.org -out server.key

配置nginx

最后标记证书使用上述私钥和CSR:

  1. $ openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

修改Nginx配置文件,让其包含新标记的证书和私钥:

  1. server {
  2.     server_name YOUR_DOMAINNAME_HERE;
  3.     listen 443;
  4.     ssl on;
  5.     ssl_certificate /usr/local/nginx/conf/server.crt;
  6.     ssl_certificate_key /usr/local/nginx/conf/server.key;
  7. }

重启nginx。
这样就可以通过以下方式访问:

https://YOUR_DOMAINNAME_HERE

另外还可以加入如下代码实现80端口重定向到443IT人乐园

  1. server {
  2. listen 80;
  3. server_name ww.centos.bz;
  4. rewrite ^(.*) https://$server_name$1 permanent;
  5. }

转载请注明文章来源:http://www.centos.bz/2011/12/nginx-ssl-https-support/

 

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SecLists

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 new version

SublimeText3 Linux latest version

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

MinGW - Minimalist GNU for Windows

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

SublimeText3 Mac version

God-level code editing software (SublimeText3)