以下是“Apache的多站点虚拟主机配置方法”的完整使用攻略,包含两个示例说明。
以下是在Apache服务器上配置站点虚拟主机的步骤:
bash
sudo mkdir /var/www/example.com
bash
sudo nano /etc/httpd/conf.d/example.com.conf
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com
ErrorLog /var/log/httpd/example.com-error.log
CustomLog /var/log/httpd/example.com-access.log combined
</VirtualHost>
这将配置一个名为example.com的虚拟主机,的根目录是/var/www/example.com,日志文件将保存在/var/log/httpd/example.com-error.log和/var/log/httpd/example.com-access.log中。
bash
sudo systemctl restart httpd.service
以下是在Apache服务器上配置第二个虚拟主机的示例:
bash
sudo mkdir /var/www/example2.com
bash
sudo nano /etc/httpd/conf.d/example2.com.conf
<VirtualHost *:80>
ServerName example2.com
ServerAlias www.example2.com
DocumentRoot /var/www/example2.com
ErrorLog /var/log/httpd/example2.com-error.log
CustomLog /var/log/httpd/example2.com-access.log combined
</VirtualHost>
bash
sudo systemctl restart httpd.service
以下是在Apache服务器上配置SSL/TLS虚拟主机的示例:
bash
sudo mkdir /var/www/ssl.example.com
bash
sudo nano /etc/httpd/conf.d/ssl.example.com.conf
<VirtualHost *:443>
ServerName ssl.example.com
ServerAlias www.ssl.example.com
DocumentRoot /var/www/ssl.example.com
ErrorLog /var/log/httpd/ssl.example.com-error.log
CustomLog /var/log/httpd/ssl.example.com-access.log combined
SSLEngine on
SSLCertificateFile /path/to/cert.pem
SSLCertificateKeyFile /path/to/key.pem
SSLCertificateChainFile /path/to/chain.pem
</VirtualHost>
这将配置一个名为ssl.example.com的SSL/TLS虚拟主机,它的根目录是/var/www/ssl.example.com,日志文件将保存在/var/logd/ssl.example.com-error.log和/var/log/httpd/ssl.example.com-access.log中。
bash
sudo systemctl restart httpd.service
希望这些步骤和示例能够帮助您在Apache服务器上配置站点虚拟主机。
本文链接:http://task.lmcjl.com/news/7351.html