nginx配置https

在配置ssl证书之前,要确保你的nginx已经安装了ssl模块,一般情况下自己安装的nginx都是不存在ssl模块的。

如果你是用yum安装的一般都会有。

 

查看 nginx 是否安装 http_ssl_module 模块。
$ /usr/local/nginx/sbin/nginx -V

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

下载 nginx 安装包, nginx官网1.14.1稳定版本tar.gz包。
# 下载安装包到 src 目录
$ cd /usr/local/src
$ wget http://nginx.org/download/nginx-1.14.1.tar.gz

解压安装包。
$ tar -zxvf nginx-1.14.1.tar.gz

配置 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

 

创建一个crt目录最好在nginx同级目录下

我的目录是/etc/nginx/conf.d/crt/

nginx.conf配置文件进行的配置

server
{
listen 80;
server_name 你的域名如:wwwbaidu.com;
return 301 https://$host$request_uri;
}

server
{
listen 443;
server_name #域名如:www.baidu.com;
underscores_in_headers on;
ssl on;
ssl_certificate /etc/nginx/conf.d/crt/证书.pem
ssl_certificate_key /etc/nginx/conf.d/crt/证书.key
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;

#下方是反向带理可以不看
location / {
proxy_connect_timeout 600;
proxy_read_timeout 600;
client_max_body_size 100m;
# proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://172.17.210.23:8041;
}


access_log /var/log/nginx/jira-53cto-com.log;
}



posted @ 2022-02-18 14:00  大海全是¥  阅读(93)  评论(0编辑  收藏  举报