yum安装nginx


nginx安装

1.添加yum源

rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

# 查看yum源
 yum repolist

2.安装nginx

yum install nginx

3.启动

# 开机自启
systemctl enable nginx
# 启动服务
 systemctl start nginx

4.打开防火墙

firewall-cmd --zone=public --permanent --add-service=http
sudo firewall-cmd --reload
# 查看所有服务
firewall-cmd --list-service

5.开启反向代理访问权限

sudo setsebool -P httpd_can_network_connect on 

6.创建配置文件,新增图片代理

vi /etc/nginx/conf.d/image.conf
server {
  listen 80;
  server_name localhost;
  location /img {
    root /home/sunlight/pic;
    autoindex on;
  }
}

问题排查

(1.) nginx绑定端口失败

localhost.localdomain nginx[9348]: nginx: [emerg] bind() to 0.0.0.0:8090 failed (13: Permission denied)
nginx.service: control process exited, code=exited status=1

解决办法

getenforce  // 查询selinux状态
setenforce 0  // 临时生效
// 永久生效
vi /etc/selinux/config
SELINUX=disabled

参考链接

https://qizhanming.com/blog/2018/08/06/how-to-install-nginx-on-centos-7


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM