2009年9月24日 星期四

筆記 / Apache 設定虛擬主機

目前都用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


沒有留言:

張貼留言

如何在 golang 裡面引用 gitlab private repo

參考文章:https://stackoverflow.com/questions/27500861/whats-the-proper-way-to-go-get-a-private-repository 原文是用 gitlab.company.com 當範例,這邊改成一般帳號...