Nginx之Https 证书加密

1.1检查NginxSSL模块是否安装

[[email protected]~]# /application/nginx/sbin/nginx -V
nginx version: nginx/1.6.3
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC)
TLS SNI support enabled
configure arguments: --prefix=/application/nginx-1.6.3 --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module

1.2准备私钥和证书

1.2.1创建服务器私钥

[[email protected]~]# cd /application/nginx/conf/
[[email protected] conf]# mkdir key
[[email protected] conf]# cd key/
[[email protected] key]# openssl genrsa -des3 -out server.key 1024
Generating RSA private key, 1024 bit long modulus
..++++++
...++++++
e is 65537 (0x10001)
Enter pass phrase for server.key:
Verifying - Enter pass phrase for server.key:

1.2.2签发证书

[[email protected] key]# openssl req -new -key server.key -out server.csr
Enter pass phrase for server.key:
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) []:BJ
Locality Name (eg, city) [Default City]:BJ
Organization Name (eg, company) [Default Company Ltd]:SDU
Organizational Unit Name (eg, section) []:SA         
Common Name (eg, your name or your server‘s hostname) []:XuBuSi
Email Address []:[email protected]
 
Please enter the following ‘extra‘ attributes
to be sent with your certificate request
A challenge password []:     
An optional company name []:

1.2.3删除服务器私钥口令

[[email protected] key]# cp server.key server.key.ori
[[email protected] key]# openssl rsa -in server.key.ori -out server.key
Enter pass phrase for server.key.ori:
writing RSA key
1.2.4生成使用签名请求证书

和私钥生成自签证书

[[email protected] key]# openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
Signature ok
subject=/C=CN/ST=BJ/L=BJ/O=SDU/OU=SA/CN=XuBuSi/[email protected]
Getting Private key

1.3开启Nginx SSL

[[email protected] ~]# cat /application/nginx/conf/vhosts/www.conf
    server {
     server_name jianguo.yi***.com;
       #listen       80;
       listen       443;
       ssl on;
       ssl_certificate key/server.crt;
       ssl_certificate_key key/server.key;
 
location / {
          roothtml/blog;
            index  index.php index.html index.htm;
        access_log /app/logs/jianguo.log main;
        }
    }

1.3.1重启nginx生效

[[email protected] ~]# /application/nginx/sbin/nginx -s reload
[[email protected] ~]# netstat -lntup|grep 443
tcp        0    0 0.0.0.0:443                 0.0.0.0:*                   LISTEN    1711/nginx

1.3.2测试https

由于该证书非第三方权威机构颁发,而是我们自己签发的,所以浏览器会警告,如果是对外的业务需要加密,必须使用商用第三方签名证书。

1.4配置重定向80端口转443端口

以上配置有个不好的地方,如果用户使用时忘了使用https或者443端口,那么将会报错,所以我们需要80端口的访问转到443端口并使用ssl加密访问。

只需要增加一个server段,使用301永久重定向。

[[email protected] ~]# tail -5 /application/nginx/conf/vhosts/www.conf
server {
        listen 80;
        server_name jianguo.yi*****.cn;
        rewrite ^(.*) https://$server_name$1 permanent;
}
[[email protected] ~]# /application/nginx/sbin/nginx -t
nginx: the configuration file /application/nginx-1.6.3/conf/nginx.conf syntax is ok
nginx: configuration file /application/nginx-1.6.3/conf/nginx.conf test is successful
[[email protected] ~]# /application/nginx/sbin/nginx -s reload
时间: 2024-08-26 11:33:00

Nginx之Https 证书加密的相关文章

nginx配置https证书

连接错误,不安全 并不是hsts的锅 chrome://net-internals/#hsts, 大部分原因还是证书的问题 NET::ERR_CERT_COMMON_NAME_INVALID 证书域名和实际访问的域名要匹配:SAN 证书中增加SAN域名 open ssl openssl genrsa -out server.key 1024 openssl req -new -x509 -days 3650 -key server.key -out server.crt -subj "/C=CN

linux nginx 安装https证书

在安装过程中,我是用Xshell这个工具来远程我的linux服务器进行操作的 1.把https证书上传到在/home/admin/cert目录下,如果没有cert这个文件夹,则需要新建 2.然后进入/etc/nginx/sites-available目录,找到这个目录下的default文件,修改里面的配置(建议先备份一下) 打开default文件: 把listen 443的这两个注释去掉,然后再加:ssl off;  这个有些资料是ssl on; 我测试了后访问http时会出现400的错误. 然

nginx切换https证书上线

server {                 listen 80;                 rewrite ^(.*)$  https://$server_name$1 permanent;                 server_name example.com;                 if ( "$host" != 'example.com' ){                         rewrite ^/(.*)$ http://exampl

Nginx 配置https证书认证

一.什么是SSL证书 SL证书全程:SSL安全通道(Secure socket layer(SSL).该安全协议主要用来提供对用户和服务器的认证:对传送的数据进行加密和隐藏:确保数据在传送中不被改变,即数据的完整性,现已成为该领域中全球化的标准. SSL证书是数字证书的一种,类似于驾驶证.护照和营业执照的电子副本.因为配置在服务器上,也称为SSL服务器证书. SSL 证书就是遵守 SSL协议,由受信任的数字证书颁发机构CA(如VeriSign),在验证服务器身份后颁发,具有服务器身份验证和数据传

自己生成nginx的https证书

#自己生成ssl证书 这里说下Linux 系统怎么通过openssl命令生成 证书. 首先执行如下命令生成一个key openssl genrsa -des3 -out ssl.key 1024 然后他会要求你输入这个key文件的密码.不推荐输入.因为以后要给nginx使用.每次reload nginx配置时候都要你验证这个PAM密码的. 由于生成时候必须输入密码.你可以输入后 再删掉. mv ssl.key xxx.key openssl rsa -in xxx.key -out ssl.ke

Cisco ASA使用证书加密

使用ASDM配置HTTPS证书加密anyconnect连接 一.在没有使用证书的情况下每次连接VPN都会出现如下提示 命令 在 ASA 上,可以在命令行中使用若干 show 命令以验证证书的状态. show crypto ca certificates命令用于查看关于您的证书.CA证书和所有注册机关(RA)证书的信息. 命令 show crypto ca trustpoints 用于验证信任点配置. 命令 show crypto key mypubkey rsa 用于显示 ASA 的 RSA 公

Nginx配置Https重定向 Chrome跳转到%2a.xxx.com的问题

今天配置Nginx的Https证书遇到了一个坑. 一般配置好证书后,都会配置一下https的重定向,让一般的http访问跳转到https访问去. 简单配置如下: server { listen 80; server_name www.sxsc.ltd sxsc.ltd stest.sxsc.ltd; return 301 https://$server_name$request_uri; } 配置好后,用chrome访问 www.sxsc.ltd 时,会莫名其妙跳转到 https://%2A.s

spring boot 1.x nginx前置https配置及注意点

首先参考nginx配置https并强制http自动跳转到https配置nginx的https证书. 然后在application.properties中加上属性如下: server.tomcat.remote_ip_header=x-forwarded-for server.tomcat.protocol_header=x-forwarded-proto server.tomcat.port-header=X-Forwarded-Port server.use-forward-headers=t

Nginx配置SSL证书部署HTTPS网站

一.什么是 SSL 证书,什么是 HTTPSSSL 证书是一种数字证书,它使用 Secure Socket Layer 协议在浏览器和 Web 服务器之间建立一条安全通道,从而实现:1.数据信息在客户端和服务器之间的加密传输,保证双方传递信息的安全性,不可被第三方窃听:2.用户可以通过服务器证书验证他所访问的网站是否真实可靠. HTTPS 是以安全为目标的 HTTP 通道,即 HTTP 下加入 SSL 加密层.HTTPS 不同于 HTTP 的端口,HTTP默认端口为80,HTTPS默认端口为44