阅读量:216
sudo vi /etc/httpd/conf.d/mydomain.conf
在mydomain.conf文件中添加以下内容:
:80 >
ServerAdmin webmaster@mydomain.com
DocumentRoot /var/www/mydomain/html
ServerName mydomain.com
ServerAlias www.mydomain.com
ErrorLog /var/log/httpd/mydomain-error.log
CustomLog /var/log/httpd/mydomain-access.log combined
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
5. 创建网站文件目录
创建网站文件的根目录,并添加一些示例文件:
sudo mkdir -p /var/www/mydomain/html
sudo echo "Welcome to My Domain" > /var/www/mydomain/html/index.html
6. 重启Apache服务
保存并关闭配置文件后,重启Apache服务以应用更改:
sudo systemctl restart httpd
7. 配置DNS
确保你的域名(例如mydomain.com)已经指向了你的服务器IP地址。你可以在你的DNS提供商的管理界面中进行配置。
8. 测试配置
打开浏览器,访问你的域名(例如),你应该能看到“Welcome to My Domain”的页面。
9. 配置SSL(可选)
如果你想为你的网站配置SSL证书,可以使用Let’s Encrypt提供的免费证书。以下是使用Certbot配置SSL的步骤:
安装Certbot:
sudo yum install certbot python2-certbot-apache
获取并安装证书:
sudo certbot --apache -d mydomain.com -d www.mydomain.com
按照提示完成配置。
完成以上步骤后,你的CentOS服务器上的Apache虚拟主机就配置完成了。