欢迎来到站长天空!

其它服务器

当前位置: 主页 > 服务器 > 其它服务器

关于Nginx配置ssl证书实现https安全访问

时间:2025-12-12 10:30:03|栏目:其它服务器|点击:

目录
  • 一、Nginx的安装与配置
    • 安装步骤
  • 二、SSL证书获取
  • 三、Nginx配置

前题条件,拥有服务器与可以解析到该服务器的自己的域名。

一、Nginx的安装与配置

若已安装好了Nginx,则需查看自己的Nginx是否开启了SSL的模块功能:

./nginx -V

关于Nginx配置ssl证书实现https安全访问

 显示如上,则代表ssl功能已开启,否则可能出现以下错误提示:

nginx: [emerg] the "ssl" parameter requires ngx_http_ssl_module in /usr/local/nginx.conf:%

安装步骤

1.官网下载nginx压缩包 nginx: download
我们先去官网下载一个最新稳定版的nginx

关于Nginx配置ssl证书实现https安全访问

然后使用xftp或者rz上传到我们的服务器

# 解压压缩包

tar -zxvf nginx-1.22.1.tar.gz

 然后进入到目录里面,查看是否有可执行权限(是不是绿色的),没有赋予执行权限

# 赋予执行权限

chmod +x configure

2.安装nginx所需要的环境

在安装之前先安装nginx所需要的一些环境

# c编译器
yum -y install gcc gcc-c++ autoconf automake make
# 解析正则的pcre库
yum install -y pcre pcre-devel
# 添加对gzip的支持
yum install -y zlib zlib-devel
# SSL
yum -y install pcre  pcre-devel zlib  zlib-devel openssl openssl-devel

3、开始安装

./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make

二、SSL证书获取

可以使用openssl.cn获取免费的证书:

百度安全验证

三、Nginx配置

将获取的ssl证书放到服务器上,配置相应的路径。

    server {
        listen       80;
        #填写绑定证书的域名
        server_name  dragonwu.xyz;
    
        #charset koi8-r;
    
        #access_log  logs/host.access.log  main;
    
        #强制将http的URL重写成https
        return 301 https://$host$request_uri;
    }
 
    server {
        listen       443 ssl;
        server_name  dragonwu.xyz; #你的域名
 
        ssl_certificate      /usr/local/ssl/dragonwu.xyz_cert_chain.pem; #证书
        ssl_certificate_key  /usr/local/ssl/dragonwu.xyz_key.key;  #证书
 
        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;
 
        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;
 
        location / {
            root   html;
            index  index.html index.htm;
        }
    }

Nginx服务器重新加载:

./nginx -s reload

关于Nginx配置ssl证书实现https安全访问

注意事项:443端口一定要打开,之前我就是因为443端口被防火墙保护,一直访问不到,开放443端口即可! 

上一篇:iis服务器如何安装ssl证书

栏    目:其它服务器

下一篇:Nginx+Keepalived怎么实现双机热备

本文标题:关于Nginx配置ssl证书实现https安全访问

本文地址:https://zz.feitang.co/server/30300.html

广告投放 | 联系我们 | 版权申明

申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:257218569 | 邮箱:257218569@qq.com

Copyright © 2018-2026 站长天空 版权所有 Powered by EyouCms冀ICP备14023439号