在Debian上綁定Apache虛擬主機域名步驟如下:
安裝Apache:
sudo apt update && sudo apt install apache2
啟用必要模塊(如需SSL):
sudo a2enmod rewrite ssl
創建虛擬主機配置文件:
在/etc/apache2/sites-available/
下新建文件(如example.com.conf
),內容示例:
<VirtualHost *:80>
ServerAdmin webmaster@example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com
<Directory /var/www/example.com>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
啟用虛擬主機:
sudo a2ensite example.com.conf
禁用默認站點(可選):
sudo a2dissite 000-default.conf
重啟Apache:
sudo systemctl restart apache2
配置DNS解析:
在域名注冊商管理面板中,添加A記錄或CNAME記錄,將域名指向服務器IP。
配置SSL(可選):
安裝Certbot并獲取證書:
sudo apt install certbot python3-certbot-apache
sudo certbot --apache -d example.com -d www.example.com
完成以上步驟后,通過瀏覽器訪問域名即可驗證綁定是否成功。