zoukankan      html  css  js  c++  java
  • 安装篇——nginx安装ssl模块转发https请求

    一、查看nginx安装的所有模块,执行命令:

      cd  /usr/local/nginx/sbin

      ./nginx -V

      是否存在模块http_ssl_module,如果已存在直接进行第三步,否则进行第二步;

    二、给已经安装的nginx添加http_ssl_module模块

      1、查看已安装的nginx版本,执行命令:

      cd /usr/local/nginx/sbin

      ./nginx -V

      2、下载对应版本的nginx源码压缩包(本人的是nginx/1.16.0),下载到目录  /usr/local  后进行编译,执行命令:

      unzip nginx-1.16.0.zip;

      cd nginx-1.16.0; 

      ./configure  ###这里添加的是原来已安装的模块,即:上文查看nginx是否安装http_ssl_module模块时查询出来的已安装模块,在结尾加上要添加的模块(例如:./configure --prefix=/usr/local/nginx --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --with-http_gzip_static_module --http-client-body-temp-path=/var/temp/nginx/client --http-proxy-temp-path=/var/temp/nginx/proxy --http-fastcgi-temp-path=/var/temp/nginx/fastcgi --http-uwsgi-temp-path=/var/temp/nginx/uwsgi --http-scgi-temp-path=/var/temp/nginx/scgi --add-module=/usr/local/fastdfs-nginx-module/src --with-http_stub_status_module --with-http_ssl_module);

      make;

      3、make完之后,也就是编译完成之后会在当前目录下的objs下生成一个刚刚编译的nginx二进制文件,将已安装nginx上的与之替换

      mv /usr/local/nginx/sbin/nginx  /usr/local/nginx/sbin/nginx_bak

      cp /usr/local/nginx-1.16.0/sbin/nginx  /usr/local/nginx/sbin/nginx

    三、安装ssl证书

      1、上传在阿里云或其他地方购买的ssl证书到nginx安装目录

      cd /usr/local/nginx

      mkdir cert

      cd cert

      rz  ####上传ssl证书

      #####配置nginx

      cd ../conf

      vim nginx.conf    #####配置如下:

    server {
            listen        443 ssl;
            server_name  域名/ip;
    
            ssl_certificate     ###证书的pem文件路径,例如(/usr/local/nginx/cert/1.pem);
            ssl_certificate_key  ###证书的key文件路径,例如(/usr/local/nginx/cert/2.key);
            ssl_session_cache    shared:SSL:1m;
            ssl_session_timeout  5m;
    ####配置的转发地址
            location /api {
              proxy_pass http://127.0.0.1:21010;
              proxy_set_header  Host $host;
              proxy_set_header   X-real-ip $remote_addr;
              proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
            }
    
        }

      2、重新启动nginx

      cd /usr/local/nginx/sbin

      ./nginx -c /usr/local/nginx/conf/nginx.conf

  • 相关阅读:
    Git本地库在哪
    Git&GitHub-添加提交以及查看状态
    linux命令——find
    正则表达式
    再访JavaScript对象(原型链和闭包)
    RabbitQM(消息队列)
    Java泛型(T)与通配符?
    Linux设置文件权限和归属
    英语单词
    RabbitQM使用笔记
  • 原文地址:https://www.cnblogs.com/zzb-yp/p/11364664.html
Copyright © 2011-2022 走看看