Nginx配置SSL
Author: Abbott Liu(刘建)
Create: 2021/09/18 5:50
Update: 2021/09/18 5:50
在咱们下载的证书文件中有一个Nginx的文件夹,这外面的两个文件都是须要的。咱们须要把这个两个文件上传到 linux 服务器中,举荐放到/etc/ssl/目录下
而后咱们须要去找到nginx的配置文件。
ps -ef | grep nginx
能够看到nginx的目录是/usr/local/nginx
那么咱们须要找到 nginx.conf文件并批改
cd /usr/local/nginx/confvim nginx.conf
配置文件内容
http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name edj365.com; rewrite ^/(.*)$ https://edj365.com:443/$1 permanent; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } # http节点中能够增加多个server节点 server { #监听443端口 listen 443 ssl; #对应的域名,把edj365.com改成你们本人的域名就能够了 server_name edj365.com; #从腾讯云获取到的第一个文件的全门路 ssl_certificate cert/edj365.com.pem; #将domain name.pem替换成您证书的文件名。 ssl_certificate_key cert/edj365.com.key; #将domain name.key替换成您证书的密钥文件名。 ssl_session_timeout 5m; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE; ssl_prefer_server_ciphers on; #这是我的主页拜访地址,因为应用的是动态的html网页,所以间接应用location就能够实现了。 location / { #文件夹 root /usr/local/nginx/html; #主页文件 index index.html; } }}
/usr/local/nginx/sbin/nginx
报错
nginx: [emerg] the "ssl" parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.conf:122
开始Nginx的SSL模块
Nginx如果未开启SSL模块,配置Https时提醒谬误
起因也很简略,nginx短少http_ssl_module模块,编译装置的时候带上--with-http_ssl_module配置就行了,然而当初的状况是我的nginx曾经装置过了,怎么增加模块,其实也很简略,往下看
做个阐明:我的nginx的装置目录是/usr/local/nginx
这个目录,我的源码包在/download/nginx-1.19.9
目录
切换到源码包:
cd /download/nginx-1.19.9# 查看nginx原有的模块/usr/local/nginx/sbin/nginx -V
在configure arguments:前面显示的原有的configure参数如下:
# 运行命令即可,等配置完./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
执行make命令,然而不要执行make install,因为make是用来编译的,而make install是装置,不然你整个nginx会从新笼罩的。
make
# 先备份,备份则不必执行cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
cp ./objs/nginx /usr/local/nginx/sbin/
而后启动nginx,仍能够通过命令查看是否曾经退出胜利
/usr/local/nginx/sbin/nginx -V
Nginx配置Http和Https共存
server { listen 80 default backlog=2048; listen 443 ssl; server_name wosign.com; root /var/www/html; ssl_certificate /usr/local/Tengine/sslcrt/ wosign.com.crt; ssl_certificate_key /usr/local/Tengine/sslcrt/ wosign.com .Key; }