Nginx 官网
wget https://nginx.org/download/nginx-1.22.1.tar.gz
编译环境:gcc make
依赖环境:
准备环境:nginx-1.22.1.tar.gz
mkdir -p /soft/src
[root@localhost ~]# ls
anaconda-ks.cfg nginx-1.22.1.tar.gz
[root@localhost ~]# mv nginx-1.22.1.tar.gz /soft/src/
[root@localhost src]# tar xf nginx-1.22.1.tar.gz
[root@localhost src]# cd nginx-1.22.1/
--prefix=PATH set installation prefix
--sbin-path=PATH set nginx binary pathname
--modules-path=PATH set modules path
--conf-path=PATH set nginx.conf pathname
--error-log-path=PATH set error log pathname
--pid-path=PATH set nginx.pid pathname
--lock-path=PATH set nginx.lock pathname
mkdir -p /soft/src
cd /soft/src
wget https://nginx.org/download/nginx-1.22.1.tar.gz
tar xf nginx-1.22.1.tar.gz
[root@localhost nginx-1.22.1]# ./configure --prefix=/soft/nginx-1.22.1
./configure: error: C compiler cc is not found
yum -y install gcc gcc-c++
./configure: error: the HTTP rewrite module requires the PCRE library.
yum install pcre-devel -y
./configure: error: the HTTP gzip module requires the zlib library.
yum install -y zlib-devel
执行命令
./configure --prefix=/soft/src/nginx-1.22.1 \
> --user=www \
> --group=www \
> --with-http_ssl_module
错误提示
./configure: error: SSL modules require the OpenSSL library
4.3.1.4.1解决方案
yum -y install openssl-devel
[root@localhost nginx-1.22.1]# echo $?
0
cd nginx-1.22.1/
make
根据makefile上的内容将源码编程二进制
[root@localhost ~]# cd /soft/src/nginx-1.22.1/
[root@localhost nginx-1.22.1]# ls
conf html logs sbin
[root@localhost nginx-1.22.1]# cd sbin/
[root@localhost sbin]# ls
nginx
[root@localhost sbin]# nginx
-bash: nginx: 未找到命令
[root@localhost sbin]# ./nginx
nginx: [emerg] getpwnam("www") failed
[root@localhost sbin]# useradd www
[root@localhost sbin]# ./nginx
[root@localhost sbin]#
[root@localhost sbin]# ps aux | grep nginx
root 17518 0.0 0.0 45996 1124 ? Ss 00:26 0:00 nginx: master process ./nginx
www 17519 0.0 0.1 46444 1872 ? S 00:26 0:00 nginx: worker process
root 17523 0.0 0.0 112824 988 pts/0 S+ 00:27 0:00 grep --color=auto nginx
#!/bin/bash
#1、安装依赖包
yum -y install gcc gcc-c++ make zlib-devel pcre-devel openssl-devel
#2、源码安装包获取
wget https://nginx.org/download/nginx-1.22.1.tar.gz
#3、解压源码包
tar xf nginx-1.22.1.tar.gz
#4、创建目录
cd ./nginx-1.22.1
mkdir -p /soft/src/
#5、安装
./configure --prefix=/soft/src/nginx-1.22.1 --user=www --group=www --with-http_ssl_module && make && make install
#6、增加用户
useradd www
cd /soft/src/nginx-1.22.1/sbin/
./nginx
#7、测试
ps aux | grep nginx