一、 rpm 配置ngnix 源
执行命令 rpm 命令,
rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
结果如图
出现上图则配置成功,,可以在/etc/yum.repos.d/ 下看到多了一个nginx.repo文件
cd /etc/yum.repos.d/
ls
二、安装ngnix
执行以下命令安装ngnix
yum install -y ngnix
启动nginix
ngnix
三、防止端口占用
启动nginx后查看他的状态
sudo systemctl status nginx
发现这个现象
find -name 'error.log'#先找到错误日志
##2024/08/21 11:24:42 [emerg] 31649#31649: bind() to 0.0.0.0:80 failed (98: Address already in use)
##2024/08/21 11:24:42 [notice] 31649#31649: try again to bind() after 500ms
##2024/08/21 11:24:42 [emerg] 31649#31649: bind() to 0.0.0.0:80 failed (98: Address already in use)
##2024/08/21 11:24:42 [notice] 31649#31649: try again to bind() after 500ms
#2024/08/21 11:24:42 [emerg] 31649#31649: bind() to 0.0.0.0:80 failed (98: Address already in use)
#这表明端口已经被占用了
lsof -i:80 #找到相对应的端口的pid,我这里显示是80
kill -9 pid #杀死进程
systemctl restart nginx#重新启动ngnix
systemctl status nginx#查看nginx状态