CentOS服务器上使用Apache托管Dotnet Core2,服务启动了,端口也打开了。在本地使用curl命令可以访问5000端口的网页内容,但是访问Apache的端口却无法获取到网页的内容。想起了之前一直踩过的坑---SE Linux。
1、首先说解决办法,运行如下命令即可:
sudo setsebool -P httpd_can_network_connect on
究其原因,这是因为SELinux(Security-Enhanced Linux)进行了访问控制的缘故。查看SELinux的文档,打开httpd_can_network_connect即可。
2、如果碰到数据库无法连接的,运行如下命令则可解决:
sudo setsebool -P httpd_can_network_connect_db on
3、如果是非生产环境,可以考虑直接关掉SELinux:
//把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