Nginx安装及配置https

Nginx安装、配置https及http转https

关于用到的crt及key文件详见 :Nginx、tomcat配置https证书申请

Nginx配置https步骤:

  1. 下载安装nginx
    下载地址:Nginx
    下载后解压到/opt目录下,进入nginx目录并使用默认配置:

    cd /opt/nginx-1.15.0 && ./configure

    安装时若未安装gcc环境,可运行如下命令进行安装:

    yum install gcc-c++

    而后安装所需的依赖库(PCRE、OPENSSL、ZLIB等等):

    yum install -y pcre pcre-devel
    yum install -y zlib zlib-devel
    yum install -y openssl openssl-devel

    再次执行配置命令:

    ./configure

    然后执行 make install编译安装

    结束后可根据命令 whereis nginx 查看安装目录,默认为:/usr/local/nginx
    进入到nginx的目录:cd /usr/local/nginx/sbin/
    可执行如下操作:

    ./nginx 开启服务
    ./nginx -s stop 停止服务(查找除nginx的进程id后执行kill关闭)
    ./nginx -s quit 待nginx进程处理好任务后再停止
    ./nginx -s reload 重启服务
    ./nginx -V 查看nginx版本及编译参数
    ./nginx -t 修改nginx配置文件nginx.conf后可用该命令来检查是否有配置错误

  2. Nginx重新编译添加ssl模块
    进入nginx的源码根目录下,即/opt/nginx-1.15.0/
    执行如下命令:

    ./configure –prefix=/usr/local/nginx –with-http_stub_status_module –with-http_ssl_module –with-file-aio –with-http_realip_module

    然后运行命令 make 进行编译
    注意:此处不用用make install命令,否则会覆盖安装

    再将新生成的nginx程序覆盖原有的nginx程序(/usr/local/nginx/sbin/nginx),此时nginx应关闭。

    检查新的nginx程序是否正确:

    /usr/local/nginx/sbin/nginx -t

    查看openssl模块是否添加成功:

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

    若成功,则其configure arguments后面不为空。

  3. 在nginx配置文件(/usr/local/nginx/conf/nginx.conf)中的server块中添加如下配置,可配置成https及http 转https
    这里写图片描述

猜你喜欢

转载自blog.csdn.net/diagnoa_wleng/article/details/82587863
今日推荐