-
首先查看/etc/httpd/conf/extra/httpd-vhosts.conf 是否存在,如果沒有需要創建一個,內容如下:
<VirtualHost *:8080>
#綁定的主域
ServerName centos7.xxx.com
#綁定的子域名
ServerAlias localhost
#網站主目錄
DocumentRoot /var/www/html/
#日誌配置
ErrorLog /var/log/httpd/error.log
CustomLog /var/log/httpd/access.log common
#ServerSignature Off
</VirtualHost>
#測試一的配置
<Directory "/var/www/html/">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory> -
確認apache的主配置文件(/etc/httpd/conf/httpd.conf)的下述配置項:
Include conf/extra/httpd-vhosts.conf
有的話取消註釋,沒有就手動加上; - 在/etc/hosts 新增 127.0.0.1 test.com www.test.com
- 給web目錄賦權限:chmod -R -t $path
- 檢測配置文件正確性:apachectl configtest
- 重啓apache:systemctl restart httpd
PS: 需要注意的是apache的httpd.conf 中:
# 該虛擬主機根目錄權限相關設置
<Directory />
# 允許根目錄中的.htaccess生效並覆蓋此處設置
AllowOverride All
# 允許該目錄的所有用戶操作權限
Require all granted
</Directory>