CentOS Apache2的安全设置包括多个方面,以下是一些关键的安全配置措施:
定期更新系统:
yum update
命令更新系统。设置和保护SSH安全:
/etc/ssh/sshd_config
文件,例如:Port 10000
PermitRootLogin no
PasswordAuthentication no
sudo systemctl restart sshd
禁用未使用的服务:
service --status-all
查看所有服务状态。iptables -L
查看所有端口规则。禁用不必要的Apache模块:
httpd.conf
文件,关闭不需要的模块。例如:# LoadModule cgi_module modules/mod_cgi.so
# LoadModule php7_module modules/libphp7.so
让Apache以指定的用户和组来运行:
httpd.conf
文件,更改默认的用户和组。例如:User apache
Group apache
防止信息泄露:
httpd.conf
文件,隐藏服务器版本信息。例如:ServerTokens Prod
ServerSignature Off
sudo systemctl restart httpd
隐藏PHP版本信息:
php.ini
文件,设置 expose_php off
。禁用自动索引模块:
httpd.conf
文件,禁用自动索引功能。例如:Options -Indexes
配置防火墙:
firewalld
配置防火墙规则,允许HTTP(80)和HTTPS(443)流量。例如:sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload
sudo systemctl enable firewalld
配置SSL/TLS:
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/pki/tls/private/server.key -out /etc/pki/tls/certs/server.crt
httpd.conf
文件,配置SSL证书和密钥路径。例如:SSLCertificateFile /etc/pki/tls/certs/server.crt
SSLCertificateKeyFile /etc/pki/tls/private/server.key
sudo systemctl restart httpd
强化用户口令:
保护口令文件:
chattr
命令给 /etc/passwd
, /etc/shadow
等文件加上不可更改属性。例如:sudo chattr +i /etc/passwd
sudo chattr +i /etc/shadow
设置root账户自动注销时限:
/etc/profile
文件中的 TMOUT
参数。例如:TMOUT=300
限制su命令:
/etc/pam.d/su
文件,限制只有特定组的用户才能使用 su
命令切换到root。例如:%pam-1.0 auth sufficient pam_wheel.so trust use uid
禁用ctrl+alt+delete重启命令:
/etc/inittab
文件,禁用 ctrl+alt+delete
组合键重启机器的命令。设置开机启动服务权限:
/etc/rc.d/init.d/
目录下所有文件的权限,确保只有root用户可以操作这些服务。防止IP欺骗和DoS攻击:
host.conf
文件和设置资源限制,如最大进程数和内存使用量。通过以上配置,可以显著提高CentOS Apache2服务器的安全性,减少潜在的安全风险。建议定期检查和更新安全设置,以应对新的安全威胁。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:centos apache2安全设置