在 CentOS 上配置 Apache(httpd),通常按以下步骤来:
sudo yum install httpd -y
(CentOS 8 也可用 dnf)
sudo dnf install httpd -y
sudo systemctl start httpd
sudo systemctl enable httpd
查看状态:
sudo systemctl status httpd
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
/etc/httpd/conf/httpd.conf/etc/httpd/conf.d//var/www/html新建配置文件:
sudo vi /etc/httpd/conf.d/example.conf
内容示例:
<VirtualHost *:80>
ServerName www.example.com
DocumentRoot /var/www/example
<Directory /var/www/example>
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
创建目录并赋权:
sudo mkdir -p /var/www/example
sudo chown -R apache:apache /var/www/example
重启 Apache:
sudo systemctl restart httpd
# 测试配置
sudo apachectl configtest
# 重启
sudo systemctl restart httpd
# 重载
sudo systemctl reload httpd
如果你是要 CentOS + PHP、HTTPS(SSL)、Apache + Tomcat 或 性能优化,可以告诉我具体需求。