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