你的问题“centos中apache如何设”比较简略,我猜你可能是想问 在 CentOS 中如何安装和配置 Apache。下面给你一个常见、实用的入门说明(以 CentOS 7/8 为例,Apache 服务名是 httpd)。
# CentOS 7/8
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
浏览器访问:
http://服务器IP
看到 Apache 默认测试页 即成功。
/etc/httpd/conf/httpd.conf
/var/www/html
把网页文件(如 index.html)放到这里。
在 /etc/httpd/conf.d/ 下新建文件,如 test.conf:
<VirtualHost *:80>
ServerName www.test.com
DocumentRoot /var/www/test
<Directory /var/www/test>
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
然后:
sudo mkdir -p /var/www/test
sudo systemctl restart httpd
systemctl start httpd # 启动
systemctl stop httpd # 停止
systemctl restart httpd # 重启
systemctl reload httpd # 平滑重载配置
如果你说的“如何设”是指:
可以告诉我具体需求,我给你更针对性的配置示例。