Nginx服务配置
安装到服务器
-
传输Nginx的tar包到root目录下
-
输入命令
tar zxvf nginx-****.tar.gz解压缩 -
切换到解压目录中
-
配置yum镜像阿里云源,推荐文章:https://blog.csdn.net/LONG_Yi_1994/article/details/141276315
-
安装C语言的编译器
yum install -y gcc -
依配置检查命令
./configure --prefix=/usr/local/nginx -
安装per库
yum install -y pcre pcre-devel -
安装zlib库
yum install -y zlib zlib-devel -
安装make库
sudo yum install make -
安装制作命令先输入
make再输入make install -
切换目录
cd /usr/local/nginx/sbin -
执行运行命令
./nginx -
sudo systemctl stop firewalld# 停止firewalld服务sudo systemctl disable firewalld# 禁用firewalld服务,使其不会开机自启
安装成系统服务
-
创建服务脚本
vi /usr/lib/systemd/system/nginx.service -
编辑内容
nginx[Unit] Description=The NGINX HTTP and reverse proxy server After=network.target remote-fs.target nss-lookup.target [Service] Type=forking PIDFile=/usr/local/nginx/logs/nginx.pid ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf 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 PrivateTmp=true [Install] WantedBy=multi-user.target -
关闭nginx服务
./nginx -s stop -
重启加载系统服务
systemctl daemon-reload -
查看系统中存在的服务中是否包含nginx
ps -ef | grep nginx -
单独开启和查看nginx服务命令状态
systemctl start nginxsystemctl status nginx -
开机启动nginx服务
systemctl enable nginx -
验证开机启动是否成功,显示enabled成功
systemctl is-enabled nginx -
重启服务器(不一定要搞这一步),
reboot
补充操作命令
nginx
./nginx #启动
./nginx -s stop #快速停止
./nginx -s quit #优雅关闭,等待客户端各项业务处理完毕后再关闭
./nginx -s reload #重置加载配置