Nginx源码包安装详解

1.源码获取

Nginx 官网

wget https://nginx.org/download/nginx-1.22.1.tar.gz

2.如何安装源码

编译环境:gcc make 
依赖环境:
准备环境:nginx-1.22.1.tar.gz

3.源码获取存放

3.1创建源码存放目录

mkdir -p /soft/src

3.2把源码移到需要存放的目录

[root@localhost ~]# ls
anaconda-ks.cfg  nginx-1.22.1.tar.gz
[root@localhost ~]# mv nginx-1.22.1.tar.gz /soft/src/

3.3解压文件

[root@localhost src]# tar xf nginx-1.22.1.tar.gz 
[root@localhost src]# cd nginx-1.22.1/

3.4常用命令介绍

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

4.源码安装实际操作

4.1官网获取源码包(一般为tar包)

mkdir -p /soft/src
cd /soft/src
wget https://nginx.org/download/nginx-1.22.1.tar.gz

4.2解压源码包

tar xf nginx-1.22.1.tar.gz 

4.3配置./configure(安装前的配置)

4.3.1安装路径

[root@localhost nginx-1.22.1]# ./configure --prefix=/soft/nginx-1.22.1

4.3.1.1错误提示

./configure: error: C compiler cc is not found
4.3.1.1.1解决方案
yum -y install gcc gcc-c++ 

4.3.1.2错误提示

./configure: error: the HTTP rewrite module requires the PCRE library.
4.3.1.2.1解决方案
yum install pcre-devel -y

4.3.1.3错误提示

./configure: error: the HTTP gzip module requires the zlib library.
4.3.1.3.1解决方案
yum install -y zlib-devel

4.3.1.4错误提示

执行命令

./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

4.3.1.4检查是成功

[root@localhost nginx-1.22.1]# echo $?
0

4.3.2功能模块检测依赖关系

4.3.3生成makefile文件

cd nginx-1.22.1/
make

4.3.4编译make

根据makefile上的内容将源码编程二进制

4.3.5安装make install

5.测试

[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

5.1网页测试

6.实际操作精简

#!/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
  • 3
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值