安装 zip
sudo yum install zip unzip -y
安装 nginx(如果服务器下载不下来,就先本地下载再上传)
cd /usr/local/src
sudo wget https://nginx.org/download/nginx-1.18.0.tar.gz
sudo tar -zxvf nginx-1.18.0.tar.gz
cd nginx-1.18.0
sudo ./configure
sudo make
sudo make install
sudo ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
添加 nginx 用户
sudo groupadd nginx
sudo useradd -g nginx nginx
nginx 命令
#启动
sudo nginx
#重启
sudo nginx -s reload
#关闭
sudo nginx -quit
开机启动 nginx
sudo vi /usr/lib/systemd/system/nginx.service
防火墙操作:
查看防火墙状态
systemctl status firewalld 或 firewall-cmd --state
暂时关闭防火墙
systemctl stop firewalld
永久关闭防火墙(慎用)
systemctl disable firewalld
开启防火墙
systemctl start firewalld
开放指定端口
firewall-cmd --zone=public --add-port=8080/tcp --permanent
关闭指定端口
firewall-cmd --zone=public --remove-port=8080/tcp --permanent
立即生效
firewall-cmd --reload
查看开放的端口
firewall-cmd --zone=public --list-ports
开机启动
切换到/lib/systemd/system/目录,创建nginx.service文件
vim nginx.service
# cd /lib/systemd/system/
# vim nginx.service
添加内容
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target
[Service]
Type=forking
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
退出并保存文件,执行systemctl enable nginx.service使nginx开机启动
# systemctl enable nginx.service
或者参考