首页 > 系统相关 >CentOS 7.9 安装 nginx-1.22.0

CentOS 7.9 安装 nginx-1.22.0

时间:2022-10-07 15:33:53浏览次数:98  
标签:http CentOS -- module devel nginx install 7.9

一、CentOS 7.9 安装 nginx-1.22.0


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

2 安装前的准备

# 操作系统内核版本
uname -a
# 操作系统发行版本
cat /etc/redhat-release

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

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下载

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

4 创建用户和组

useradd nginxxyz -s /sbin/nologin
id nginxxyz

 

二、解压


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

 

三、配置编译模块

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

cd /opt/nginx-1.22.0
./configure   # 不带参数,默认会安装到 /usr/local/nginx 目录,也可以 指定参数。
./configure --prefix=/usr/local/nginx  # 则会在安装的时候,安装到 /usr/data/nginx 的目录  。
./configure \
--user=nginxxyz \
--group=nginxxyz \
--with-threads \
--with-file-aio \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_xslt_module=dynamic \
--with-http_image_filter_module=dynamic \
--with-http_geoip_module=dynamic \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_auth_request_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_degradation_module \
--with-http_slice_module \
--with-http_stub_status_module \
--with-stream=dynamic \
--with-stream_ssl_module \
--with-stream_realip_module \
--with-stream_geoip_module=dynamic \
--with-stream_ssl_preread_module \
--with-compat  \
--with-pcre-jit \
--prefix=/usr/local/nginx

 

四、编译&安装


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

 

五、修改环境变量


将nginx服务加入环境变量

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

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

 

六、启动


# 启动nginx
nginx
# 重启nginx
nginx -s reload
# 停止nginx
nginx -s stop

 

七、自启动


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

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

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

[Unit]
Description=nginx
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=true

[Install]
WantedBy=multi-user.target

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

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

systemctl enable nginx.service

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

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

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

# 查看运行状态
systemctl status nginx

其他命令

# 启动 nginx
systemctl start nginx
# 停止 nginx
systemctl stop nginx
# 重新加载 nginx
systemctl reload nginx

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

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

 

八、nginx 配置


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

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

 

九、防火墙


# 关闭防火墙
systemctl stop firewalld

# 开放3306端口命令
firewall-cmd --zone=public --add-port=3306/tcp --permanent
# 配置立即生效
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

 

标签:http,CentOS,--,module,devel,nginx,install,7.9
From: https://www.cnblogs.com/huaxiayuyi/p/16759643.html

相关文章

  • 关于Centos-8.X-操作系统不能使用yum源的解决方法
    今天笔者准备做一些实验时,发现Centos8.x操作系统不能使用官方的yum源了,提示:Error:Failedtodownloadmetadataforrepo'appstream':Cannotprepareinternalmirro......
  • Linux 常用命令 CentOS
    网络相关ipaddr//查看网络及网卡编号systemctlrestartnetwork//重启网络vi/etc/sysconfig/network-scripts/ifcfg-网卡编号//修改网络相关配置ifconfig//查看......
  • CentOS8修改网卡名
    目录前期说明前期说明今天在部署OpenStackKolla版本时因为一台机的网卡名不对导致一直提示有错误,故修改了下网卡名,这里做个简单的记录需要将下图中的ens224改成ens1......
  • CentOS 7.9 安装 redis-6.2.0
    一、CentOS7.9安装redis-6.2.01下载地址:https://download.redis.io/releases/redis-6.2.0.tar.gz 2安装gcc来进行编译Redis由C语言编写,所以需要系统中有gcc......
  • 01 Docker安装Docker CE安装--CentOS8
    Docker当前有两个版本:社区版(CommunityEdition,CE)和企业版(EnterpriseEdition,EE)。DockerCE是免费的,一个基于moby项目的开源的容器版本。DockerEE包含DockerCE中......
  • 06 RustDesk搭建个人远程桌面中继服务器(centos)
    官方文档RustDesk官方文档<--建议仔细阅读整篇文档。安装配置一、服务器安装步骤运行hbbs、hbbr以下方法任选其一。PS.在运行hbbs和hbbr的时候添加-k_参数,禁止没有......
  • nginx 一些简单访问控制模块
    nginx已经内置了一些简单的访问控制模块,利用好这些模块我们可以提升系统的安全几个比较有用的标准模块基本都是利用了access阶段的能力limit_except限制请求方法的(类似白......
  • nginx proxy webservie 问题&实践
    webservice具有特殊性,因为wsdl文件是服务器端生成的(大部分,而且是动态的),所以我们直接使用nginx进行proxy会有问题实际上此问题比较常见,而且网上也有人碰到,可能因为时间......
  • 一次nginx 请求真实ip 问题处理
    nginxngx_http_realip模块是比较重要的,我以前也大概说过,同时网上关于此模块的资料也不少,今天就碰到了一个获取真实ip的问题记录下参考业务模型  问题以前的配置,waf......
  • nginx ngx_http_addition_module 模块openresty content_by_lua 不能生效的原因
    nginx的ngx_http_addition_module模块也是一个修改content的好东西,对于openresty我们经常使用content_by_lua阶段处理但是经过分析ngx_http_addition_module源码的......