目前都用name-based居多ip-based很少用就不寫了

環境設定
# mkdir -p /var/www/slv922
# echo "test for VirtualHost" > /var/www/html/index.html

重要提示:如欲在家目錄中建立網頁資料夾,務必更改家目錄權限為711 or 755才可存取

名稱解析
有架設dns的請到dns中新增別名,序號記得改
www        IN    A                 192.168.1.2
slv922      IN    CNAME        www
# service named restart

沒dns的設定/etc/hosts
#vi /etc/hosts
192.168.1.2                www.test.org      slv922.test.org

重要提示: 名稱解析記得一定要設定,很多人會先設定httpd.conf ,設定好就忘記設定名稱解析的部分了

設定檔部分
# vi /etc/httpd/conf/httpd.conf

ServerName www.test.org

NameVirtualHost *:80

<VirtualHost *:80>
      ServerName www.test.org
      DocumentRoot /var/www/html
</VirtualHost>

<VirtualHost *:80>
      ServerName slv922.test.org
      DocumentRoot /var/www/slv922
</VirtualHost>

# service httpd restart

重要提示: 第一組的VirtualHost設定不能省略,否則會出問題

測試
分別瀏覽 http://www.test.org , http://slv922.test.org
如果網頁資料夾不是在/var/www/中,會在瀏覽http://slv922.test.org時出現阻擋訊息,

SELinux 規則設定
方法1
# restorecon -R -v '/var/www/slv922'

方法2
# chcon -R -t httpd_sys_content_t /var/www/slv922

arrow
arrow
    全站熱搜

    slv922 發表在 痞客邦 留言(1) 人氣()