nginx部署测试
#安装程序和依赖
yum install -y vim net-tools wget
yum -y install gcc pcre-devel zlib-devel openssl openssl-devel
#下载nginx
mkdir /opt/nginx
cd /opt/nginx
wget https://nginx.org/download/nginx-1.20.2.tar.gz
#解压
tar zxvf nginx-1.20.2.tar.gz
cd nginx-1.20.2
#配置
./configure --prefix=/usr/local/nginx
#编译
make && make install
vim /usr/local/nginx/conf/nginx.conf
#改端口号为81
创建软连接
ln -s /usr/local/nginx/sbin/nginx /usr/bin
systemctl stop firewalld
nginx -s reload
配置systemd方式管理NG
vim /usr/lib/systemd/system/nginx.service
填入
[Unit]
Description=The Nginx HTTP 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=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
systemctl restart nginx.service
如果报错:Job for nginx.service failed because the control process exited with error code. See “systemctl status nginx.service” and “journalctl -xe” for details.
kill 30789
systemctl daemon-reload
systemctl start nginx
nginx -s reload