Centos7 中Nginx的安裝與配置

 

 

安裝與配置

1.安裝nginx

yum intsall nginx
啓動服務
sudo systemctl start nginxsudo firewall-cmd --permanent --zone=public --add-service=http 容許http通訊 sudo firewall-cmd --permanent --zone=public --add-service=https  容許https通訊 sudo firewall-cmd --reload 從新加載配置

2.配置

在 /etc/nginx/conf.d 目錄中新建一個my.conf文件,在此以前先將nginx.conf 配置文件中的server節點註釋掉nginx

server {
        listen 80; #映射端口 location / { proxy_pass http://localhost:5000; #監聽端口 proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection keep-alive; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; } }

3.使用新配置啓動nginx

執行這兩個命令中的任一個重置nginx網絡

 nginx -s reload  從新加載配置文件
 systemctl  nginx restart  重啓nginx

4.訪問網站

此時經過80端口訪問網站應該是一切正常,但不凡意外發生ide

異常狀況502

進入 /var/log/nginx/ 目錄中查看錯誤日誌,若是是如下錯誤,能夠嘗試用下面的方法解決學習

getsebool -a |grep httpd_can_network_connect //檢查http網絡訪問權限狀況

咱們能夠看到它是關閉狀態的網站

執行 setsebool -P httpd_can_network_connect 1 //開啓網絡訪問權限

開啓後 http_can_network_connect 狀態爲onspa

此時在訪問應該不會再有問題了,此文僅爲學習時記錄,我本身重現了三次,應該是沒什麼問題的。最後 跟jesse 一塊兒學習.Net Core 。
相關文章
相關標籤/搜索