CentOS服務器上使用Apache託管Dotnet Core2,服務啓動了,端口也打開了。在本地使用curl命令能夠訪問5000端口的網頁內容,可是訪問Apache的端口卻沒法獲取到網頁的內容。想起了以前一直踩過的坑---SE Linux。linux
一、首先說解決辦法,運行以下命令便可:數據庫
sudo setsebool -P httpd_can_network_connect on
究其緣由,這是由於SELinux(Security-Enhanced Linux)進行了訪問控制的緣故。查看SELinux的文檔,打開httpd_can_network_connect便可。服務器
二、若是碰到數據庫沒法鏈接的,運行以下命令則可解決:curl
sudo setsebool -P httpd_can_network_connect_db on
三、若是是非生產環境,能夠考慮直接關掉SELinux:url
//把SELINUX設置爲disabled便可
vi /etc/sysconfig/selinux
# This file controls the state of SELinux on the system. # SELINUX= can take one of these three values: # enforcing - SELinux security policy is enforced. # permissive - SELinux prints warnings instead of enforcing. # disabled - No SELinux policy is loaded. #SELINUX=enforcing #把設置改成disabled SELINUX=disabled # SELINUXTYPE= can take one of these two values: # targeted - Targeted processes are protected, # mls - Multi Level Security protection. SELINUXTYPE=targeted