在CentOS/RHEL7操作系统上编译安装Nginx并配置服务

这篇文章主要讲述的是在CentOS/RHEL7操作系统上编译安装Nginx并配置服务,本文档硬件采用VMware Workstation Pro虚拟机模拟,安装步骤与现实环境无异。关于虚拟机的安装及配置不过多阐述,本文主要讲述Nginx编译安装配置和服务配置过程。

一,环境准备

本文中提及的所有软件如何获取将在本章节讲解,如仅仅是需要参考如何编译安装Nginx请直接到Nginx官网下载软件后,跳转到本文第二章节“安装编译环境”开始阅读。
(一)VMware Workstation Pro下载
本文使用VMware Workstation Pro 17来模拟服务器硬件环境,如果需要获取该软件可以访问“VMware Workstation Pro 17 下载文章获取。
(二)操作系统下载
本文使用了RedHat Enterprise Linux(RHEL)7.9来安装Nginx,如果需要获取该操作系统可以访问“操作系统下载”筛选获取。
(三)Nginx下载
编写本文时Nginx的稳定版本为nginx-1.22.1,如果有幸能被你看到这篇文章,你可以访问“Nginx官网”获取最新版本的软件。

二,安装编译环境

[root@shizhanxia.com nginx-1.22.1]#yum -y install gcc wget automake autoconf libtool libxml2-devel libxslt-devel perl-devel perl-ExtUtils-Embed pcre-devel openssl-devel make 

三,编译安装Nginx

1,下载最新的Nginx版本

[root@shizhanxia.com nginx-1.22.1]#wget http://nginx.org/download/nginx-1.22.1.tar.gz

2,然后就是将下载下来的Nginx解压缩。

[root@shizhanxia.com nginx-1.22.1]# tar zxvf nginx-1.22.1.tar.gz

3,进入解压缩后的Nginx目录。如果你要定制版本号可以更改源码目录src/core/nginx.h文件。

[root@shizhanxia.com nginx-1.22.1]#cd nginx-1.22.1/

4,创建一个nginx目录用来存放运行的临时文件夹。

[root@shizhanxia.com nginx-1.22.1]#mkdir -p /etc/nginx
[root@shizhanxia.com nginx-1.22.1]#mkdir -p /var/cache/nginx
[root@shizhanxia.com nginx-1.22.1]#useradd app01

5,开始configure Nginx。

[root@shizhanxia.com nginx-1.22.1]#
./configure \
--prefix=/etc/nginx \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--http-client-body-temp-path=/var/cache/nginx/client_temp \
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
--user=app01 \
--group=app01 \
--with-pcre \
--with-http_v2_module \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--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_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-mail \
--with-mail_ssl_module \
--with-file-aio \
--with-ipv6 \
--with-http_v2_module \
--with-threads \
--with-stream \
--with-stream_ssl_module

6,接着继续编译。

[root@shizhanxia.com nginx-1.22.1]#make

7,安装Nginx。

[root@shizhanxia.com nginx-1.22.1]#make install

在CentOS/RHEL7操作系统上编译安装Nginx并配置服务8,配置systemctl控制的Nginx服务,将以下下内容复制输入到新建的nginx.service文件中。

剩余内容需解锁观看

解锁查看全文

立即回复
已经回复?立即刷新

原创文章,作者:保哥,如若转载,请注明出处:https://www.shizhanxia.com/593.html

(0)
保哥保哥黄金会员
上一篇 2023年2月7日
下一篇 2023年2月9日

相关推荐

发表回复

登录后才能评论

评论列表(1条)