栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

Nginx 配置 HTTPS

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Nginx 配置 HTTPS

配置站点使用 https,并且将 http 重定向至 https。

1. nginx 的 ssl 模块安装

查看 nginx 是否安装 http_ssl_module 模块,如果出现 configure arguments: --with-http_ssl_module, 则已安装(下面的步骤可以跳过,进入 nginx.conf 配置)。

$ /usr/local/nginx/sbin/nginx -V

配置 ssl 模块

$ cd nginx-1.14.1
$ ./configure --prefix=/usr/local/nginx --with-http_ssl_module

使用 make 命令编译(使用make install会重新安装nginx),此时当前目录会出现 objs 文件夹。
用新的 nginx 文件覆盖当前的 nginx 文件。

$ cp ./objs/nginx /usr/local/nginx/sbin/

再次查看安装的模块(configure arguments: --with-http_ssl_module说明ssl模块已安装)。

$ /usr/local/nginx/sbin/nginx -V

nginx version: nginx/1.14.1

configure arguments: –with-http_ssl_module

2. nginx.conf 配置

ssl证书文件(server.pem、server.key)放在/data/cert/目录下,nginx.conf配置如下:

server {
    listen 5000 ssl;
    #ssl证书的pem文件路径
    ssl_certificate  /data/cert/server.pem;
    #ssl证书的key文件路径
    ssl_certificate_key /data/cert/server.key;

    location / {
        root   D:webPage;
	    #root   D:gitcodeWebbase-js;
        #autoindex on;
    }

}
3. 重启Nginx
nginx -t
nginx -s reload

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/451248.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号