Nginx 编译安装
安装环境:
rocky8.0
**安装前将防火墙和selinux关闭**
**文件中有注释的地方,复制时记得删除掉**
官方包地址:http://nginx.org/en/linux_packages.html
#下载包
wget http://nginx.org/download/nginx-1.22.1.tar.gz
#安装依赖包
yum -y install gcc pcre-devel openssl-devel zlib-devel
#创建NGINX专用账号
useradd -s /sbin/nologin nginx
#解压并进入目录
tar xf nginx-1.22.1.tar.gz
cd nginx-1.22.1
#功能选择及安装
./configure --prefix=/apps/nginx \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-pcre \
--with-stream \
--with-stream_ssl_module \
--with-stream_realip_module
make && make install
#Nginx目录结构
[root@Rocky8 nginx-1.22.1]# tree /apps/nginx/
/apps/nginx/
├── conf
│ ├── fastcgi.conf
│ ├── fastcgi.conf.default
│ ├── fastcgi_params
│ ├── fastcgi_params.default
│ ├── koi-utf
│ ├── koi-win
│ ├── mime.types
│ ├── mime.types.default
│ ├── nginx.conf
│ ├── nginx.conf.default
│ ├── scgi_params
│ ├── scgi_params.default
│ ├── uwsgi_params
│ ├── uwsgi_params.default
│ └── win-utf
├── html
│ ├── 50x.html
│ └── index.html
├── logs
└── sbin
└── nginx
#创建 Nginx 自启动文件
vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
[Service]
Type=forking
PIDFile=/apps/nginx/run/nginx.pid #指定pid文件的目录,默认在logs目录下,可选配置
ExecStart=/apps/nginx/sbin/nginx -c /apps/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
LimitNOFILE=100000
[Install]
WantedBy=multi-user.target
#创建pid文件存放的目录
mkdir /apps/nginx/run/
#修改配置文件指定pid文件路径
vim /apps/nginx/conf/nginx.conf
pid /apps/nginx/run/nginx.pid;
#验证自启动文件
systemctl daemon-reload
systemctl enable --now nginx
ss -ntl
#重启测试自启动文件是否生效
reboot
#安装完成后如果没有nginx命令执行一下方法
[root@Rocky8 ~]# nginx -h
bash: nginx: command not found...
Install package 'nginx' to provide command 'nginx'? [N/y] n
[root@Rocky8 ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@Rocky8 ~]# vim /etc/profile
export PATH=$PATH:/apps/nginx/sbin #根据nginx的安装路径填写
标签:编译,nginx,--,apps,module,Nginx,conf,http,安装
From: https://www.cnblogs.com/zhangsy714/p/16925872.html