你这个问题比较宽泛,我分几种常见场景给你讲,都是 CentOS + Apache(httpd) 的实用配置。
yum install httpd -y
systemctl start httpd
systemctl enable httpd
dnf install httpd -y
systemctl start httpd
systemctl enable httpd
防火墙放行:
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload
/var/www/html/etc/httpd/conf/httpd.conf/etc/httpd/conf.d/例如配置 www.example.com
mkdir -p /var/www/example
echo "hello example" > /var/www/example/index.html
新建配置文件:
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>
重启 Apache:
systemctl restart httpd
yum install mod_ssl -y
vi /etc/httpd/conf.d/ssl.conf
关键配置:
SSLCertificateFile /path/to/cert.crt
SSLCertificateKeyFile /path/to/private.key
或虚拟主机方式:
<VirtualHost *:443>
ServerName www.example.com
DocumentRoot /var/www/example
SSLEngine on
SSLCertificateFile /path/to/cert.crt
SSLCertificateKeyFile /path/to/private.key
</VirtualHost>
AllowOverride All
Options -Indexes
DirectoryIndex index.php index.html
systemctl status httpd
journalctl -xe
httpd -t # 检查配置语法
如果你是指:
告诉我,我可以给你更精准的一步到位配置。