在CentOS 7.9上安装Nginx 1.24.0的步骤

下载 Nginx wgethttps://nginx.org/download/nginx-1.24.0.tar.gz
tar-xzfnginx-1.24.0.tar.gz
cdnginx-1.24.0
配置编译参数 ./configure --prefix=/usr/local/nginx
编译和安装 make
sudo make install
创建Nginx服务文件 sudo vi /etc/systemd/system/nginx.service
[Unit]
Description=Nginx-server
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID

[Install]
WantedBy=multi-user.target
设置启动脚本权限和服务 sudo chmod +x /etc/systemd/system/nginx.service
sudo systemctl daemon-reload
sudo systemctl enable nginx
启动Nginx sudo systemctl start nginx
检查Nginx状态 sudo systemctl status nginx
开放80 端口 sudo firewall-cmd --permanent --add-port=80/tcp
重新加载防火墙规则 sudo firewall-cmd --reload
posted @ 2024-06-05 10:06  何童鞋  阅读(116)  评论(0编辑  收藏  举报