技术分享
首页
  • JavaScript

    • 构造函数和原型
    • Cookie和Session
    • Object.create(null)和{}
    • TypeScript配置
    • typescript入门到进阶
  • 框架

    • Vue-Router
    • React基础入门
  • 其它

    • Http协议
    • 跨域问题总结
  • 分析Promise实现
  • Axios源码分析
  • Webpack原理
  • vueRouter源码分析
  • Vue

    • Vite快速搭建Vue3+TypeScript项目
    • Cordova打包Vue项目的问题
    • Vue将汉字转为拼音,取出首字母
    • h5项目问题总结
  • JavaScript

    • new Function
  • 后端

    • Node.js中使用Crypto生成Token
    • Body-Parser处理多层对象的问题
  • 其它

    • 项目Demo汇总
    • Vuepress+Vercel搭建个人站点
    • 项目中能用到的
    • husky规范代码提交
  • Mongoose基础
  • Multer文件上传中间件的使用
  • JavaScript

    • 浅谈两数全等
    • JavaScript进制转换
    • 手写bind,apply,call和new
  • 算法

    • 数组去重和排序
    • 数组扁平化
    • 斐波那契数列
  • JavaScript 数据结构
  • 其它

    • webpack面试题
    • vite面试题
    • svg和canvas的优缺点
    • TypeScript面试题
    • Vue常见面试题
  • 计算机网络

    • 数据链路层
    • 网络层
  • Git的使用
  • Nginx的使用
  • CentOS7安装Nginx
  • 正则表达式
  • SEO搜索引擎优化
  • Serverless介绍
友链
GitHub (opens new window)

刘誉

总有人要赢,为什么不能是我
首页
  • JavaScript

    • 构造函数和原型
    • Cookie和Session
    • Object.create(null)和{}
    • TypeScript配置
    • typescript入门到进阶
  • 框架

    • Vue-Router
    • React基础入门
  • 其它

    • Http协议
    • 跨域问题总结
  • 分析Promise实现
  • Axios源码分析
  • Webpack原理
  • vueRouter源码分析
  • Vue

    • Vite快速搭建Vue3+TypeScript项目
    • Cordova打包Vue项目的问题
    • Vue将汉字转为拼音,取出首字母
    • h5项目问题总结
  • JavaScript

    • new Function
  • 后端

    • Node.js中使用Crypto生成Token
    • Body-Parser处理多层对象的问题
  • 其它

    • 项目Demo汇总
    • Vuepress+Vercel搭建个人站点
    • 项目中能用到的
    • husky规范代码提交
  • Mongoose基础
  • Multer文件上传中间件的使用
  • JavaScript

    • 浅谈两数全等
    • JavaScript进制转换
    • 手写bind,apply,call和new
  • 算法

    • 数组去重和排序
    • 数组扁平化
    • 斐波那契数列
  • JavaScript 数据结构
  • 其它

    • webpack面试题
    • vite面试题
    • svg和canvas的优缺点
    • TypeScript面试题
    • Vue常见面试题
  • 计算机网络

    • 数据链路层
    • 网络层
  • Git的使用
  • Nginx的使用
  • CentOS7安装Nginx
  • 正则表达式
  • SEO搜索引擎优化
  • Serverless介绍
友链
GitHub (opens new window)
  • Git的使用
  • SEO搜索引擎优化
  • 常用cmd和linux命令
  • 代码片段
  • Serverless
  • CentOS7安装Nginx
    • 添加 ssl 证书
      • 问题
  • GitHub Actions 自动化部署
  • Nginx的使用
  • 正则表达式
  • vscode调试总结
  • 其它
coderly
2021-03-28

CentOS7安装Nginx

# CentOS7 安装 Nginx

记一次 CentOS7 安装 Nginx 过程

  1. 安装 gcc
  • 查看版本:gcc -v
  • 安装命令:yum -y install gcc
  1. 安装 pcre、pcre-devel

nginx 的 http 模块使用 pcre 来解析正则表达式

  • yum install -y pcre pcre-devel
  1. zlib 安装
  • yum install -y zlib zlib-devel
  1. 安装 openssl

web 安全通信的基石

  • yum install -y openssl openssl-devel
  1. 安装 Nginx

查看 Nginx 版本 (opens new window)
选择一个稳定版本

  • 切换到 /usr/local 目录:cd /usr/local
  • wget -c https://nginx.org/download/nginx-1.18.0.tar.gz
  • 解压:tar -zxvf nginx-1.18.0.tar.gz
  • cd nginx-1.18.0
  • 执行以下 3 个命令
# 使用默认配置
./configure

# 编译安装
make
make install
1
2
3
4
5
6
  • 查找安装路径: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.conf后使用该命令,新配置即可生效

# 重启nginx,建议先停止,再启动
./nginx -s stop
./nginx
1
2
3
4
5
6
7
8
  • 查看 nginx 服务是否启动成功:ps -ef | grep nginx

# 安装上传下载命令 rz 和 sz

yum install lrzsz -y

# 安装 unzip

yum install -y unzip zip

# 添加 ssl 证书

以阿里云为例

  • 阿里云免费购买地址 (opens new window)
  • 点 "选购证书" 进入购买页面
ssl图片
  • 进入证书管理 (opens new window)页面,选择下载 Nginx 版本
ssl下载图片
  • 先关闭 Nginx: /usr/local/nginx/sbin/nginx -s stop
  • 下载后将会得到 .key 和 .pem 两个文件,将证书上传到服务器 /usr/local/nginx/conf/ssl 下(例子)
    https 默认端口为 443,在 server 添加如下内容


 


 
 

 
 

 
 






 




server {
      listen       80;
      listen       443 ssl default;
      server_name  localhost;

      ssl_certificate      ./ssl/5393413_coderly.cn.pem; # 上传的 .pem 文件(相对路径或绝对路径)
      ssl_certificate_key  ./ssl/5393413_coderly.cn.key; # 上传的 .key 文件(相对路径或绝对路径)

      ssl_session_cache    shared:SSL:1m;
      ssl_session_timeout  5m;

      ssl_ciphers  HIGH:!aNULL:!MD5;
      ssl_prefer_server_ciphers  on;

      server_name  localhost;

      #access_log  logs/host.access.log  main;

      location / {
          root   /usr/web/html/blog; # 选择你网站根目录
          index  index.html index.htm;
      }
  }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  • 重新启动 Nginx:/usr/local/nginx/sbin/nginx

# 问题

  1. the "ssl" parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.conf:37

提示

nginx 缺少 http_ssl_module 模块,编译安装的时候带上–with-http_ssl_module 配置就行了

  • 执行命令:/usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.18.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
configure arguments:
# arguments 参数为空, 所以报错
1
2
3
4
  • 优先关闭 nginx:/usr/local/nginx/sbin/nginx -s stop

  • cd nginx-1.18.0

  • 重新执行新配置信息
    ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module

  • make

  • 重新启动:/usr/local/nginx/sbin/nginx

如果上述操作之后还是报错

  • 备份 nginx 配置
  • 删除 nginx
  • 重新 安装
上次更新: 2021/03/29, 09:49:46
Serverless
GitHub Actions 自动化部署

← Serverless GitHub Actions 自动化部署→

最近更新
01
代码片段
04-22
02
koa全家桶
03-29
03
mocks项目复盘
03-29
更多文章>
Theme by Vdoing | Copyright © 2021-2022 coderly | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式