nginx实现https访问

nginx实现https访问

  1. 创建服务器证书密钥文件 server.key:
[root@localhost ~]# openssl genrsa -des3 -out server.key 1024
#输入密码,确认密码
  1. 创建服务器证书的申请文件 server.csr
[root@localhost ~]# openssl req -new -key server.key -out server.csr
#输出内容如下
Enter pass phrase for root.key: ← 输入前面创建的密码
Country Name (2 letter code) [AU]:CN ← 国家代号,中国输入CN
State or Province Name (full name) [Some-State]:BeiJing ← 省的全名,拼音
Locality Name (eg, city) []:BeiJing ← 市的全名,拼音
Organization Name (eg, company) [Internet Widgits Pty Ltd]:MyCompany Corp. ← 公司英文名
Organizational Unit Name (eg, section) []: ← 可以不输入
Common Name (eg, YOUR name) []: ← 此时不输入
Email Address []:admin@mycompany.com ← 电子邮箱,可随意填
Please enter the following ‘extra’ attributes
to be sent with your certificate request
A challenge password []: ← 可以不输入
An optional company name []: ← 可以不输入
  1. 备份一份服务器密钥文件
[root@localhost ~]# cp server.key server.key.org
  1. 去除文件口令
[root@localhost ~]# openssl rsa -in server.key.org -out server.key
  1. 生成证书文件server.crt
[root@localhost ~]# openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
  • nginx配置文件(部分)
 server {
        listen       80;
        server_name  localhost;
        listen 443 ssl;
        ssl_certificate         /usr/local/nginx/ssl/server.crt;
        ssl_certificate_key     /usr/local/nginx/ssl/server.key;
  }
  • nginx如果未开启SSL模块,配置https时提示错误
nginx[emerg]the"ssl"parameterrequiresngx_http_ssl_moule in/usr/local/nginx/conf/nginx.conf

nginx缺少http_ssl_module模块,编译安装的时候带上–with-http_ssl_module

  • 服务器已经安装过nginx,但是未安装http_ssl_module模块
[root@localhost ~]# cd /root/nginx-1.14.0
[root@nginx-1.14.0 ~]# ./configure --with-http_stub_status_module --with-http_ssl_module
  • 编译
[root@nginx-1.14.0 ~]# make
#不需要执行make install,否则就覆盖安装了
  • 备份原有的nginx
[root@nginx-1.14.0 ~]# cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx_bak
  • 将刚刚编译好的nginx覆盖掉原有的nginx(nginx需要停止)
[root@nginx-1.14.0 ~]# cp ./objs/nginx /usr/local/nginx/sbin/
  • 查看安装情况
[root@nginx-1.14.0 ~]# /usr/local/nginx/sbin/nginx -V
  • 启动服务
[root@nginx-1.14.0 ~]# /usr/local/nginx/sbin/nginx 
  • 访问

访问

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值