Nginx开启SSL支持https

本文详述如何使用Let’s Encrypt免费证书为Nginx开启SSL支持。教程包括检查Nginx配置、确认域名解析正确、安装必要软件、获取并配置证书,最后修改nginx配置文件实现全站HTTPS访问。
摘要由CSDN通过智能技术生成

本文教程使用了Let’s Encrypt免费证书

先检查Nginx的配置

执行 nginx -V

-bash-4.2# nginx -V
nginx version: nginx/1.15.8
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'

检查配置里是否有--with-http_ssl_module

保证你申请SSL的域名和服务器的IP是一致的,即域名确实是解析到你的服务器上的,可以使用nslookup命令查询。

执行 nslookup www.yourwebsite.com

如果提示-bash: nslookup: command not found ,则需要执行下面的命令

yum install bind-utils

-bash-4.2# yum install bind-utils
...
Installed:
  bind-utils.x86_64 32:9.9.4-73.el7_6                                                                                                                                  

Dependency Installed:
  bind-libs.x86_64 32:9.9.4-73.el7_6                                                                                                                                   

Complete!

安装完成在执行nslookup www.yourwebsite.com

-bash-4.2# nslookup pangge.info
Server:		xxx.xxx.xxx.xxx
Address:	xxx.xxx.xxx.xxx#xx

Non-authoritative answer:
Name:	xxxxx.xxxx				<--- 检查这个是否和你的域名一致
Address: xx.xxx.xxx.xxx			<--- 这个检查是否和你服务器的IP一致

Let’s Encrypt在给你分配证书时,会检查你所在的服务器是否和域名解析的服务器一致。

安装git和bc,yum install -y git bc

执行 yum -y install yum-utils

执行 yum-config-manager --enable rhui-REGION-rhel-server-extras rhui-REGION-rhel-server-optional

执行 yum install certbot python2-certbot-nginx

执行 yum install -y git python27

执行 yum install -y augeas-libs dialog gcc libffi-devel openssl-devel python-devel

执行 yum install python-argparse

执行 service nginx stop

执行 certbo

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值