zoukankan      html  css  js  c++  java
  • linux部署带ssl的nginx

    1.前期准备

    1.1:下载nginx-1.18.0版本  http://nginx.org/download/nginx-1.18.0.tar.gz  然后上传到服      务器 /usr/local/src 目录下
    1.2:安装编译工具及库文件

    1. //一键安装四个依赖

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

    1.3:安装 PCRE PCRE 作用是让 Nginx 支持 Rewrite 功能 

    1. 进入到安装目录
    2.  cd /usr/local
    3.  下载pcre-8.35
    4.  wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
    5.  解压安装包:
    6.  tar zxvf pcre-8.35.tar.gz
    7.  进入安装包目录
    8. cd pcre-8.35
    9.  编译安装
    10.  ./configure
    11.  make && make install
    12.  查看pcre版本
    13.  pcre-config --version
    14.  查看pcre版本
    15.  rpm -qa pcre

    2.nginx安装

    2.1:进入到nginx文件目录

    cd /usr/local/src/

    2.2:解压安装包

    tar -zxvf nginx-1.18.0.tar.gz

    2.3:进入安装包目录

    cd nginx-1.18.0

    2.4:编译安装

    1.  将nginx编译安装到/usr/local/nginx下
    2.  ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/pcre-8.35
    3.  make   
    4.  make install

    2.5:查看nginx版本

    /usr/local/nginx/sbin/nginx -v

    2.6:nginx常见命令

    /usr/local/nginx/sbin/nginx                         启动

    /usr/local/nginx/sbin/nginx -s stop             关闭

    /usr/local/nginx/sbin/nginx -s reload          重启


    3.SSL配置 

    3.1:如果我们使用SSL证书需要引用到nginx的中SSL这个模块
    上述nginx安装的时候加了./configure --prefix=/usr/local/nginx --with-                                  http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/pcre-8.35 其中 --with-http_ssl_module就是添加ssl模块 如果没有加ssl模块可以添加这个模块就好了
    3.2:要有SSL对应的 公钥和自私 放到指定文件夹下 /usr/ssl

    service.crt # 公钥

    service.key # 私钥  

    3.3:修改nginx配置文件

    1.  
      cd /usr/local/nginx/conf
    2.  
      vi nginx.conf
    3.  
      //修改443端口文件
    4.  
      http{
       
      #http节点中可以添加多个server节点
       
      server{
       
      #监听443端口
       
      listen 443;
       
      #对应的域名,把domain.com改成你们自己的域名就可以了
       
      server_name domain.com;
       
      ssl on;
       
      #公钥路径
       
      ssl_certificate /usr/ssl/service.crt;
       
      #私钥路径
       
      ssl_certificate_key /usr/ssl/service.key;
       
      ssl_session_timeout 5m;
       
      ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
       
      ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
       
      ssl_prefer_server_ciphers on;
       
      location / {
       
      root /usr/local/service/ROOT;
       
      index index.html;
       
      }
       
      }
       
      server{
       
      listen 80;
       
      server_name domain.com;
       
      rewrite ^/(.*)$ https://domain.com:443/$1 permanent;
       
      }
       
      }
    5.  

    3.4:重启nginx就可以了

    一.错误
    configure: error: You need a C++ compiler for C++ support.
     安装c++ compiler

    [root@localhost]# yum install -y gcc gcc-c++

    -bash: wget: command not found 错误

    yum -y install wget

    启动报错 nginx: [error] invalid PID number "" in "/usr/local/nginx/logs/nginx.pid"

    解决方法: [root@localhost nginx]/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

    报错  

    make: *** No targets specified and no makefile found. Stop. 解决方法

    yum install gcc gcc-c++ autoconf automake

    yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel (安装依赖zlib、openssl和pcre)

    然后再走

        
  • 相关阅读:
    MFC OnPaint()函数中最先调用CDialog::OnPaint()和最后调用CDialog::OnPaint()的巨大区别
    教你如何快速使用Github
    NET开发者部署React-Native
    分层架构
    微内核架构(Microkernel Architecture)
    ABP-N层架构
    MVC 应用免受 CSRF攻击
    Redis时延问题
    JS call与apply
    jQuery插件编写
  • 原文地址:https://www.cnblogs.com/xuefeilong/p/14343513.html
Copyright © 2011-2022 走看看