赞
踩
#!/bin/bash
## 安装java运行环境及依赖项
yum install -y java gcc gcc-c++ autoconf automake make zlib zlib-devel openssl openssl-devel pcre pcre-devel wget httpd-tools vim -y
## 下载nginx
curl -OL https://nginx.org/download/nginx-1.25.3.tar.gz
##解压nginx
tar -zxvf nginx-1.25.3.tar.gz
## 创建安装目录
mkdir /usr/local/nginx
## 切换到nginx源码目录
cd /home/nginx-1.25.3
## 配置安装目录
./configure --prefix=/usr/local/nginx
## 编译安装nginx
make -j 4 && make install
## 创建软链接
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin
## 防火墙放通端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --zone=public --add-port=443/tcp --permanent
systemctl restart firewalld
## 配置ngixn服务
cat <<EOF >/usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
[Install]
WantedBy=multi-user.target
EOF
## 重新载入systemctl
systemctl daemon-reload
## 启动nginx服务
systemctl start nginx
## 设置开机启动
systemctl enable nginx
## 展示安装成功消息
echo "Nginx has been installed and configured."
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。