未加星标

Nginx配置HTTPS证书网站

字体大小 | |
[系统(linux) 所属分类 系统(linux) | 发布者 店小二05 | 时间 20160901 | 作者 红领巾 ] 0人收藏点击收藏

前提:

1、主机要先安装openssl

2、编译安装nginx时,要加上--with-openssl和--with-http_ssl_module

1、生成自签字证书
[[email protected] /]# openssl req -new -x509 -keyout /root/ca.key -out /root/ca.crt
Generating a 2048 bit RSA private key
.............+++
...................................+++
writing new private key to '/root/ca.key'
Enter PEM pass phrase: #输入密钥保护密码
Verifying - Enter PEM pass phrase: #确认密码保护密码
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:guangzhou
Locality Name (eg, city) [Default City]:guangzhou
Organization Name (eg, company) [Default Company Ltd]:linuxidc
Organizational Unit Name (eg, section) []:it
Common Name (eg, your name or your server's hostname) []:101.codesec.net
Email Address []:[email protected]

2、修改配置文件openssl.cnf

vim /etc/pki/tls/openssl.cnf
[ ca ]
default_ca = CA_default # The default ca section

####################################################################
[ CA_default ]

dir = /etc/pki/CA #证书的根目录,要记住这个目录
certs = $dir/certs
crl_dir = $dir/crl
database = $dir/index.txt
#unique_subject = no
new_certs_dir = $dir/newcerts

certificate = $dir/ca.crt # 修改这里,表示签名时使用的证书
serial = $dir/serial
crlnumber = $dir/crlnumber
crl = $dir/crl.pem
private_key = $dir/private/cakey.pem
RANDFILE = $dir/private/.rand
3、复制证书到证书根目录/etc/pki/CA下,并在该目录下创建空文件index.txt和serial,并向serial输入”01“
cd /etc/pki/CA
cp /root/ca.crt .
touch index.txt
touch serial
echo "01" >serial

4、生成服务器RSA私钥/root/server.key

openssl genrsa -des3 -out /root/server.key 1024

5、为私钥去除口令
openssl rsa -in /root/server.key -out /root/server_nopwd.key
5、生成证书请求文件/root/server.csr
[[email protected] /]# openssl req -new -key /root/server.key -out /root/server.csr
Enter pass phrase for /root/server.key: #输入第4步生成的密钥的保护密码
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
--------下面这部分应该和创建私有证书时填的一样------------------------
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:guangzhou
Locality Name (eg, city) [Default City]:guangzhou
Organization Name (eg, company) [Default Company Ltd]:linuxidc
Organizational Unit Name (eg, section) []:it
Common Name (eg, your name or your server's hostname) []:101.codesec.net
----------------------------------------------------------------
Email Address []:[email protected]

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:www.codesec.net
An optional company name []:linuxidc
6、用私有证书给证书请求文件/root/server.csr签名
[[email protected] CA]# openssl ca -in /root/server.csr -out /root/server.crt -cert /root/ca.crt -keyfile /root/ca.key -config /etc/pki/tls/openssl.cnf
Using configuration from /etc/pki/tls/openssl.cnf
Enter pass phrase for ca.key:
Check that the request matches the signature
Signature ok
Certificate Details:
Serial Number: 1 (0x1)
Validity
Not Before: Aug 31 14:09:15 2016 GMT
Not After : Aug 31 14:09:15 2017 GMT
Subject:
countryName = CN
stateOrProvinceName = guangzhou
organizationName = linuxidc
organizationalUnitName = it
commonName = 101.codesec.net
emailAddress = [email protected]
X509v3 extensions:
X509v3 Basic Constraints:
CA:FALSE
Netscape Comment:
OpenSSL Generated Certificate
X509v3 Subject Key Identifier:
18:80:30:B7:C6:11:61:AE:F3:62:9D:D0:33:D9:97:CB:45:5A:31:91
X509v3 Authority Key Identifier:
keyid:DA:99:4B:9B:29:A8:D8:14:54:FA:52:4B:1E:C3:E0:81:C6:A6:EF:42

Certificate is to be certified until Aug 31 14:09:15 2017 GMT (365 days)
Sign the certificate? [y/n]:yes


out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated
7、编辑nginx配置文件/etc/nginx/nginx.conf
-------在配置文件的特定区域加入/修改下面内容
server {
listen 443 ssl; #设置监听的端口
server_name linuxidc;
ssl on;
ssl_certificate /root/server.crt;
ssl_certificate_key /root/server_nopwd.key;
8、重启服务
~~~~完成,在客户端上输入https://x.x.x.x即可访问

--------------------------------------分割线 --------------------------------------

Nginx负载均衡配置实战 http://www.codesec.net/Linux/2014-12/110036.htm

CentOS 6.2实战部署Nginx+mysqlphp http://www.codesec.net/Linux/2013-09/90020.htm

使用Nginx搭建WEB服务器 http://www.codesec.net/Linux/2013-09/89768.htm

搭建基于Linux6.3+Nginx1.2+PHP5+MySQL5.5的Web服务器全过程 http://www.codesec.net/Linux/2013-09/89692.htm

CentOS 6.3下Nginx性能调优 http://www.codesec.net/Linux/2013-09/89656.htm

CentOS 6.3下配置Nginx加载ngx_pagespeed模块 http://www.codesec.net/Linux/2013-09/89657.htm

CentOS 6.4安装配置Nginx+Pcre+php-fpm http://www.codesec.net/Linux/2013-08/88984.htm

Nginx安装配置使用详细笔记 http://www.codesec.net/Linux/2014-07/104499.htm

Nginx日志过滤 使用ngx_log_if不记录特定日志 http://www.codesec.net/Linux/2014-07/104686.htm

--------------------------------------分割线 --------------------------------------

Nginx 的详细介绍:请点这里
Nginx 的下载地址:请点这里

本文地址:http://www.codesec.net/Linux/2016-09/134826.htm


Nginx配置HTTPS证书网站

本文系统(linux)相关术语:linux系统 鸟哥的linux私房菜 linux命令大全 linux操作系统

分页:12
转载请注明
本文标题:Nginx配置HTTPS证书网站
本站链接:http://www.codesec.net/view/481911.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 系统(linux) | 评论(0) | 阅读(25)