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

2023-12-07 0 912
目录
  • 一、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端口即可!

      到此这篇关于关于Nginx配置ssl证书实现https安全访问的文章就介绍到这了,更多相关Nginx配置ssl证书安全访问内容请搜索悠久资源以前的文章或继续浏览下面的相关文章希望大家以后多多支持悠久资源!

      收藏 (0) 打赏

      感谢您的支持,我会继续努力的!

      打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
      点赞 (0)

      悠久资源 Nginx服务器 关于Nginx配置ssl证书实现https安全访问 https://www.u-9.cn/server/nginx/114760.html

      常见问题

      相关文章

      发表评论
      暂无评论
      官方客服团队

      为您解决烦忧 - 24小时在线 专业服务