centos7下apache2.4.6虛擬主機配置

  1. 首先查看/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>

  2. 確認apache的主配置文件(/etc/httpd/conf/httpd.conf)的下述配置項:
    Include conf/extra/httpd-vhosts.conf
    有的話取消註釋,沒有就手動加上;

  3. 在/etc/hosts 新增 127.0.0.1 test.com www.test.com
  4. 給web目錄賦權限:chmod -R -t $path
  5. 檢測配置文件正確性:apachectl configtest
  6. 重啓apache:systemctl restart httpd

PS: 需要注意的是apache的httpd.conf 中:

# 該虛擬主機根目錄權限相關設置
<Directory />
    # 允許根目錄中的.htaccess生效並覆蓋此處設置
    AllowOverride All
    # 允許該目錄的所有用戶操作權限
    Require all granted
</Directory>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章