nginx一键部署编译安装

发布时间:2023年12月30日

#!/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"

文章来源:https://blog.csdn.net/anguoan/article/details/135152478
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。