一、CentOS 7.9 安装 nginx-1.22.0


下载地址:http://nginx.org/en/download.html

2 安装前的准备

  1. # 操作系统内核版本
  2. uname -a
  3. # 操作系统发行版本
  4. cat /etc/redhat-release

在安装Nginx之前,我们需要确保安装Nginx所依赖的其他程序,执行下面的命令,安装或更新相应的程序。

  1. yum install -y make zlib zlib-devel gcc-c++ libtool openssl openssl-devel pcre pcre-devel libxslt-devel geoip-devel gd gd-devel

执行完成后,如果之前未安装的,则会自动安装,如果之前已经安装有旧的版本,则会被新的版本代替。

3 wget下载

  1. # 推荐wget下载
  2. yun install -y wget
  3. wget http://nginx.org/download/nginx-1.22.0.tar.gz

4 创建用户和组

  1. useradd nginxxyz -s /sbin/nologin
  2. id nginxxyz

二、解压


  1. tar -zxvf /opt/software/nginx-1.22.0.tar.gz -C /opt/ # 解压
  2. cd /opt/nginx-1.22.0 # 进入nginx目录

三、配置编译模块

使用 ll 可以看到目录下有 configure 的可执行文件,这个文件的作用,就是根据你系统的情况,生成makefile的,以便于下一步的编译和安装

  1. cd /opt/nginx-1.22.0
  2. ./configure # 不带参数,默认会安装到 /usr/local/nginx 目录,也可以 指定参数。
  3. ./configure --prefix=/usr/local/nginx # 则会在安装的时候,安装到 /usr/data/nginx 的目录  。
  1. ./configure \
  2. --user=nginxxyz \
  3. --group=nginxxyz \
  4. --with-threads \
  5. --with-file-aio \
  6. --with-http_ssl_module \
  7. --with-http_v2_module \
  8. --with-http_realip_module \
  9. --with-http_addition_module \
  10. --with-http_xslt_module=dynamic \
  11. --with-http_image_filter_module=dynamic \
  12. --with-http_geoip_module=dynamic \
  13. --with-http_sub_module \
  14. --with-http_dav_module \
  15. --with-http_flv_module \
  16. --with-http_mp4_module \
  17. --with-http_gunzip_module \
  18. --with-http_gzip_static_module \
  19. --with-http_auth_request_module \
  20. --with-http_random_index_module \
  21. --with-http_secure_link_module \
  22. --with-http_degradation_module \
  23. --with-http_slice_module \
  24. --with-http_stub_status_module \
  25. --with-stream=dynamic \
  26. --with-stream_ssl_module \
  27. --with-stream_realip_module \
  28. --with-stream_geoip_module=dynamic \
  29. --with-stream_ssl_preread_module \
  30. --with-compat \
  31. --with-pcre-jit \
  32. --prefix=/usr/local/nginx

四、编译&安装


  1. make
  2. make install # 这两行可以分开执行,也可以在同一行执行
  3. make && make install # 同一行执行

五、修改环境变量


将nginx服务加入环境变量

在文件中添加 nginx 的安装路径下的bin 目录

  1. vim /etc/profile
  2. export PATH=$PATH:/usr/local/nginx/sbin
  3. # 使配置文件生效
  4. source /etc/profile

六、启动


  1. # 启动nginx
  2. nginx
  3. # 重启nginx
  4. nginx -s reload
  5. # 停止nginx
  6. nginx -s stop

七、自启动


很多时候,我们为了方便管理,在服务器重启后,需要nginx自动启动,那么我们可以添加 nginx 的服务

  1. # 创建 nginx 服务文件
  2. vim /lib/systemd/system/nginx.service

nginx 的服务文件配置可参考如下:

  1. [Unit]
  2. Description=nginx
  3. After=network.target
  4. [Service]
  5. Type=forking
  6. ExecStart=/usr/local/nginx/sbin/nginx
  7. ExecReload=/usr/local/nginx/sbin/nginx -s reload
  8. ExecStop=/usr/local/nginx/sbin/nginx -s stop
  9. PrivateTmp=true
  10. [Install]
  11. WantedBy=multi-user.target

完成后,按ESC键,输入:wq 保存并退出,上面的nginx 相应的目录,需要改为你自己的目录。

服务文件配置好了,接下来要把它添加到服务里面。

  1. systemctl enable nginx.service

执行完后,系统会在下方提示:

  1. Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.

看到这个,nginx 的服务就已经完成添加,但这个时候,还没有启动的,我们可以通过下面的命令来操作nginx。

  1. # 查看运行状态
  2. systemctl status nginx

其他命令

  1. # 启动 nginx
  2. systemctl start nginx
  3. # 停止 nginx
  4. systemctl stop nginx
  5. # 重新加载 nginx
  6. systemctl reload nginx

如果重新修改 nginx.service 配置文件后,则需要使用下面的命令来重新加载服务的配置文件。

  1. # 重新加载服务的配置文件
  2. systemctl daemon-reload

八、nginx 配置


使用源码安装方式,nginx的配置文件,通常会在  /usr/local/nginx/conf/nginx.conf  这个位置,可以通过 vi 或 vim 修改。

  1. # 打开配置文件
  2. vim /usr/local/nginx/conf/nginx.conf

九、防火墙


  1. # 关闭防火墙
  2. systemctl stop firewalld
  3. # 开放3306端口命令
  4. firewall-cmd --zone=public --add-port=3306/tcp --permanent
  5. # 配置立即生效
  6. firewall-cmd --reload

云主机需配置安全组(默认已放行,可省略)

在入方向规则,允许80放行

十、问题记录


错误:./configure: error: the HTTP rewrite module requires the PCRE library.

解决:安装pcre-devel:yum -y install pcre-devel

错误:./configure: error: the HTTP cache module requires md5 functions

from OpenSSL library. You can either disable the module by using 
–without-http-cache option, or install the OpenSSL library into the system, 
or build the OpenSSL library statically from the source with nginx by using 
–with-http_ssl_module –with-openssl= options.

解决:yum -y install openssl openssl-devel

错误:./configure: error: the HTTP XSLT module requires the libxml2/libxslt    缺少libxml2

解决:yum -y install libxml2 libxml2-devel && yum -y install libxslt-devel

错误信息:./configure: error: the HTTP image filter module requires the GD library. You can either do not enable the module or install the libraries.

解决方法:http_image_filter_module是nginx提供的集成图片处理模块,需要gd-devel的支持   yum -y install gd-devel

错误信息:./configure: error: perl module ExtUtils::Embed is required 缺少ExtUtils

解决方法:yum -y install perl-devel perl-ExtUtils-Embed

错误信息:./configure: error: the GeoIP module requires the GeoIP library. You can either do not enable the module or install the library. 缺少GeoIP

解决方法:yum -y install GeoIP GeoIP-devel GeoIP-data

错误信息:./configure: error: the Google perftools module requires the Google perftools
library. You can either do not enable the module or install the library.

解决方法:yum -y install gperftools

CentOS 7.9 安装 nginx-1.22.0的更多相关文章

  1. CentOS 7.4安装Nginx 1.14.0

    一.安装所需环境   1.gcc 安装         yum install gcc-c++    

  2. CentOS 6.5安装Erlang/OTP 17.0

    CentOS 6.5安装Erlang/OTP 17.0 作者:chszs,转载需注明.博客主页:http://blog.csdn.net/chszs Erlang眼下已经是Fedora和Debian/ ...

  3. Linux系统运维笔记(四),CentOS 6.4安装Nginx

    Linux系统运维笔记(四),CentOS 6.4安装Nginx 1,安装编译工具及库文件 yum -y install make zlib zlib-devel gcc-c++ libtool op ...

  4. Centos 7下安装nginx,使用yum install nginx,提示没有可用的软件包

    Centos 7下安装nginx,使用yum install nginx,提示没有可用的软件包. 18 (flaskApi) [root@67 flaskDemo]# yum -y install n ...

  5. CentOS 6 中安装Node.js 4.0 版本或以上

    如果想在CentOS 6 中安装Node.js >4.0,如果通过以往的方式安装: wget http://nodejs.org/dist/v4.0.0/node-v4.0.0.tar.gz t ...

  6. 在CentOS 7中安装nginx服务器

    简要地介绍一下,如何在CentOS 7中安装nginx服务器  下载对应当前系统版本的nginx包(package) # wget  http://nginx.org/packages/centos/ ...

  7. 如何在 CentOS 7 上安装 Nginx

    本文首发:开发指南:如何在 CentOS 7 上安装 Nginx Nginx 读作 engine x, 是一个免费的.开源的.高性能的 HTTP 和反向代理服务,主要负责负载一些访问量比较大的站点. ...

  8. CentOS 7 源代码安装Nginx

    本篇简要介绍CentOS 7 源代码安装Nginx. Preface # yum install epel-release -y # yum group install "Developme ...

  9. centos 下yum 安装nginx

    centos 下yum 安装nginx 1. 直接yum install nginx不行,要先处理下源: rpm -ivh http://nginx.org/packages/centos/6/noa ...

  10. centos 7 安装 git 2.22.0

    1.安装所需软件包 yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel yum install gcc ...

随机推荐

  1. 算法竞赛进阶指南0x41并查集

    并查集简介 并查集的两类操作: Get 查询任意一个元素是属于哪一个集合. Merge 把两个集合合并在一起. 基本思想:找到代表元. 注意有两种方法: 使用一个固定的值(查询方便,但是在合并的时候需 ...

  2. docker Compose 部署springboot+vue前端端分离项目

    温馨提示:如果有自己的服务器最好不过了,这样部署网项目就可以上线了.没有的话,只能使用localhost 本机访问啦,记得替换 ngixn 中的ip地址.域名为localhost. (一) 准备工作 ...

  3. placeholder 设置字体颜色

    input::-webkit-input-placeholder { /* WebKit browsers */ color: #999; } input:-moz-placeholder { col ...

  4. Luogu4391 [BOI2009]Radio Transmission 无线传输 (KMP)

    \(最小循环节\) \(=\) \(lenghth - next[lenghth]\) #include <iostream> #include <cstdio> #inclu ...

  5. 刷题记录:Codeforces Round #734 (Div. 3)

    Codeforces Round #734 (Div. 3) 20210920.网址:https://codeforces.com/contest/1551. 编程细节:下标定义不要一会[1,n]一会 ...

  6. [CF1519C] Berland Regional (数论分块)

    题面 有 n 个学生和 n 所大学,每个学生在其中一所大学中学习,且各有一个能力值 s i s_i si​ . 某次组队打比赛的召集令会给一个数字 k ,表示团队数量.然后每所大学会先把自己的所有学生 ...

  7. 造序列(构造,DP)

    题面 Sample Input 7 8 7 10 31 20 100 869120 Sample Output 6 1 1 4 5 1 4 7 1 9 1 9 8 1 0 8 1 9 4 9 1 0 ...

  8. 【java】学习路径29-异常捕捉实例

    import java.util.ArrayList;public class ExceptionCatchDemo { public static void main(String[] args) ...

  9. 【c#语言简单算法】1-角谷猜想

    角谷猜想 算法目的 一个正整数x,如果是奇数就乘以3再加1,如果是偶数就析出偶数因数2ⁿ,这样经过若干个次数,最终回到1. 这里计算0-100的所有计算过程 代码实现 for (int n = 1; ...

  10. 实践分享!GitLab CI/CD 快速入门

    用过 GitLab 的同学肯定也对 GitLab CI/CD 不陌生,GitLab CI/CD 是一个内置在 GitLab 中的工具,它可以帮助我们在每次代码推送时运行一系列脚本来构建.测试和验证代码 ...