一场Nginx https配置调试过程

栏目: 服务器 · Nginx · 发布时间: 6年前

内容简介:原文链接:测试环境为:阿里云 centos7.4 ,nginx1.14.3,其他版本的系统或者nginx如有不同,以官网为准。最开始参考阿里云栖社区的这篇

原文链接: 何晓东 博客

测试环境为:阿里云 centos7.4 ,nginx1.14.3,其他版本的系统或者nginx如有不同,以官网为准。

开始配置

最开始参考阿里云栖社区的这篇 文章 ,在阿里云控制面板进行配置,然后对应修改 nginx.conf 文件,执行 nginx -s reload 重载使之生效。

nginx.conf https配置

server {
    listen 443;
    server_name www.domain.com;
    ssl on;
    root html;
    index index.html index.htm;
    ssl_certificate   cert/domain.pem;
    ssl_certificate_key  cert/domain.key;
    ssl_session_timeout 5m;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    location / {
        root html;
        index index.html index.htm;
    }
}

一番操作之后域名 https://www.domain.com 不能访问,可怕了,开始排错。

检查配置和本地端口

检查域名,证书位置,其他参数有没有写错的主要是看一下,没有发现错误。

使用 nginx -t 测试配置

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

nginx 自身的测试没有报错。

检查本机端口监听

使用 netstat -anp |grep 443 命令,检查443端口监听,结果:

tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 15940/nginx: master 也正常,所以问题出在外部网络端口上。

检查防火墙端口及安全组规则

前提条件,使用 telnet www.domain.com 443 请求 443 端口,报错 443 端口无法链接,所以开放 443 端口可以访问。

检查安全组设置直接参考 官方文档 , 如果安全组没有 443 端口,加上并且允许访问就行,现在多少是默认开启的。

firewall添加443端口使用以下命令:

firewall-cmd --list-ports
#output 80/tcp
firewall-cmd --zone=public --add-port=443/tcp --permanent
firewall-cmd --reload

重载生效,理想情况下不会有什么问题了,然后浏览器访问还是无法连接。

在命令行下,执行 curl https://www.domain.com 检查情况,返回报错:

curl https://www.domain.com
curl: (35) SSL received a record that exceeded the maximum permissible length.

直接谷歌报错信息,MD,nginx 高版本需要端口和 ssl 需要在一行,改为 listen 443 ssl 然后去掉 ssl on 这行,再次 nginx -s reload 生效,一切正常了。搜到文章说 ssl on 这行在 nginx 1.15 版本中会报错,没去验证了,高版本 nginx 将这两个写在一行就行。

最终配置为:

server {
    listen 443 ssl;
    server_name www.domain.com;
    # 其他配置不变
    
    ...
}

参考链接: 官方文档

学习更多知识

© 原创文章


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Data Structures and Algorithms with JavaScript

Data Structures and Algorithms with JavaScript

Michael McMillan / O'Reilly Media / 2014-2-22 / USD 28.51

If you’re using JavaScript on the server-side, you need to implement classic data structures that conventional object-oriented programs (such as C# and Java) provide. This practical book shows you how......一起来看看 《Data Structures and Algorithms with JavaScript》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

SHA 加密
SHA 加密

SHA 加密工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具