源码安装nginx


下载nginx

### 访问nginx官网(nginx.org-----》download)复制下载连接
# 下载源码包
wget https://nginx.org/download/nginx-1.24.0.tar.gz

# 解压源码包
tar xf nginx-1.24.0.tar.gz

# 创建工作目录
mkdir /app

# 移动nginx目录到工作目录
mv /root/nginx-1.24.0 /app

# 进入工作目录nginx
cd /app/nginx-1.24.0/

# 生成
./configure --prefix=/opt/nginx-1.24.0 --with-http_ssl_module --withhttp_stub_status_module

--prefix=/opt/nginx-1.24.0 指定了安装目录,这意味着 Nginx 将被安装在 /opt/nginx-1.24.0 目录下
--with-http_ssl_module 表示在编译时包含 SSL 模块,这允许 Nginx 支持 HTTPS 协议
--with-http_stub_status_module 表示包含状态模块,它允许你通过一个特定的 URL 来获取 Nginx 的状态信息。
条命令是在编译 Nginx 时,指定了安装路径和包含了 SSL 支持以及状态信息模块的选项。这样配置后,你就可以使用 HTTPS 来提供安全的网页服务,并且能够监控 Nginx 的运行状态了。

# 问题1.缺号pcre的依赖
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.
## 解决方案
yum install -y pcre-devel

# 再次执行生成命令
./configure --prefix=/opt/nginx-1.24.0 --with-http_ssl_module --withhttp_stub_status_module


# 问题2 缺少openssl的依赖
./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option.
## 解决方案
yum install -y openssl-devel

# 出现如下内容就代表生成完毕
Configuration summary
+ using system PCRE library
+ using system OpenSSL library
+ using system zlib library
nginx path prefix: "/opt/nginx-1.24.0"
nginx binary file: "/opt/nginx-1.24.0/sbin/nginx"
nginx modules path: "/opt/nginx-1.24.0/modules"
nginx configuration prefix: "/opt/nginx-1.24.0/conf"
nginx configuration file: "/opt/nginx-1.24.0/conf/nginx.conf"
nginx pid file: "/opt/nginx-1.24.0/logs/nginx.pid"
nginx error log file: "/opt/nginx-1.24.0/logs/error.log"
nginx http access log file: "/opt/nginx-1.24.0/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp


# 编译 (让系统能够识别你的代码)
make


# 安装
make install


# 添加软链接
ln -s /opt/nginx-1.24.0/ /opt/nginx

# 添加环境变量
vim /etc/profile.d/nginx.sh
export NGINX_PATH=/opt/nginx/sbin
export PATH=$PATH:$NGINX_PATH

# 生效环境变量
source /etc/profile

# 检验环境变量
[root@web02 nginx-1.24.0]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/opt/nginx/sbin:/opt
/nginx-1.26.0/sbin


# 启动nginx
nginx

# 检查进程
[root@web02 nginx-1.24.0]# ps -ef | grep nginx
root 17899 1 0 11:57 ? 00:00:00 nginx: master process nginx
nobody 17900 17899 0 11:57 ? 00:00:00 nginx: worker process

# 检查端口
[root@web02 nginx-1.24.0]# netstat -lntup | grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN
17899/nginx: master

# 访问nginx页面
10.0.0.8