1.前置工作
1.1 下载包
zlib-1.3.1.tar.gz
openssl-3.2.2.tar.gz
pcre2-10.44.tar.gz
nginx-1.26.2.tar.gz
2.创建目录
# 创建⽬录
mkdir -p /data/nginx/logs
chmod 755 /root # 重要配置
chown -R root:root /data/nginx
3.解压安装包
# 前提条件,取决于nginx版本问题,由于⽐较⾼,需要单独下载较新的依赖包(zlib、pcre、openssl)
# 解压主包和依赖包
tar zxf $HOME/setup/zlib-1.3.1.tar.gz -C $HOME/setup/
tar zxf $HOME/setup/openssl-3.2.2.tar.gz -C $HOME/setup/
tar zxf $HOME/setup/pcre2-10.44.tar.gz -C $HOME/setup/
tar zxf $HOME/setup/nginx-1.26.2.tar.gz -C $HOME/setup/
4.部署nginx-1.26.0
cd $HOME/setup/nginx-1.26.2
./configure \
--prefix=$HOME/nginx-1.26.2 \
--with-http_ssl_module \
--with-pcre=$HOME/setup/pcre2-10.44 \
--with-zlib=$HOME/setup/zlib-1.3.1 \
--with-openssl=$HOME/setup/openssl-3.2.2 \
--with-http_stub_status_module
make -j4
make install
5.配置nginx
5.1 编辑nginx.conf文件
# 配置nginx.conf
mkdir $HOME/nginx-1.26.2/conf/sites
vi $HOME/nginx-1.26.2/conf/nginx.conf
# 根据CPU逻辑核个数来设置
worker_processes 1;
# 指定错误⽇志
error_log /data/nginx/logs/error.log;
# 指定pid⽂件
pid /data/nginx/logs/nginx.pid;
# 新增配置
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" $request_time';
# 新增配置
access_log /data/nginx/logs/host.access.log main;
# 末尾新增
include sites/*.conf;
5.2 编辑子配置文件
vi $HOME/nginx-1.26.2/conf/sites/default.conf
server {
listen 8000;
server_name localhost;
charset utf-8;
access_log /data/nginx/logs/default.access.log main;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
6.创建脚本
mkdir $HOME/yunwei
6.1 创建启动脚本
# 启动脚本
vi $HOME/yunwei/nginx-1.26.2_start.sh
#!/bin/bash
cd $HOME/nginx-1.26.2/sbin
./nginx -c $HOME/nginx-1.26.2/conf/nginx.conf
6.2 创建停止脚本
# 停⽌脚本
vi $HOME/yunwei/nginx-1.26.2_stop.sh
#!/bin/bash
cd $HOME/nginx-1.26.2/
./sbin/nginx -s stop
6.3 创建reload脚本
vi $HOME/yunwei/nginx-1.26.2_reload.sh
#!/bin/bash
cd $HOME/nginx-1.26.2/
./sbin/nginx -s reload
7.验证nginx
ps -ef|grep nginx
root 29823 1 0 19:44 ? 00:00:00 nginx: master process ./nginx -c
/root/nginx-1.26.2/conf/nginx.conf
nobody 29824 29823 0 19:44 ? 00:00:00 nginx: worker process
标签:tar,部署,setup,nginx,conf,HOME,1.26
From: https://www.cnblogs.com/imTxl/p/18512078