nginx一键部署编译安装

#!/bin/bash

# Step 1: Download Nginx source code
echo "Step 1: Downloading Nginx source code..."
wget http://nginx.org/download/nginx-1.12.2.tar.gz

# Step 2: Extract the tar.gz file
echo "Step 2: Extracting the tar.gz file..."
tar -xzvf nginx-1.12.2.tar.gz

# Step 3: Change directory to the Nginx source directory
cd nginx-1.12.2

# Step 4: Install required dependencies
echo "Step 4: Installing required dependencies..."
yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel

# Step 5: Configure Nginx
echo "Step 5: Configuring Nginx..."
./configure --with-http_ssl_module --with-stream

# Step 6: Build and install Nginx
echo "Step 6: Building and installing Nginx..."
make && make install

# Step 7: Change directory back to the script's directory
cd ..

# Step 8: Create the systemd service file
echo "Step 8: Creating the systemd service file..."
cat <<EOL > /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
EOL

# Step 9: Enable Nginx as a system service
echo "Step 9: Enabling Nginx as a system service..."
systemctl enable nginx

# Step 10: Start Nginx
echo "Step 10: Starting Nginx..."
systemctl start nginx

# Step 11: Check the status of Nginx
echo "Step 11: Checking the status of Nginx..."
systemctl status nginx

echo "配置文件路径:/usr/local/nginx/conf"
echo "检查配置文件:/usr/local/nginx/sbin/nginx -t"
echo "重新加载配置:/usr/local/nginx/sbin/nginx -s reload"

  • 23
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

远方有海,小样不乖

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值