2008年9月22日 星期一

Debian Apache2設定

  • 安裝apache2

    debian:~# apt-get install apache2

  • 設定使用者個人目錄

    debian:~# cd /etc/apache2/mods-enabled/
    debian:/etc/apache2/mods-enabled# ln -s ../mods-available/userdir.conf userdir.conf
    debian:/etc/apache2/mods-enabled# ln -s ../mods-available/userdir.load userdir.load

  • 設定VirtualHost

    debian:# cd /etc/apache2/sites-enabled
    debian:/etc/apache2/sites-enabled# vi 000-default

    fix

    <VirtualHost *>
    ServerAdmin root@myurl.org
    ServerName www.myurl.org
    DocumentRoot /var/www/
    <Directory /var/www/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride AuthConfig
    Order allow,deny
    allow from all
    # This directive allows us to have apache2's default start page
    # in /apache2-default/, but still have / go to the right place
    #RedirectMatch ^/$ /apache2-default/
    </Directory>
    </VirtualHost>

    重啟apache2

    /etc/init.d/apache2 restart

  • 加上htpasswd驗證

    需將網站的設定為AllowOverride AuthConfig

    debian:~# cd /var/www
    debian:/var/www# htpasswd -c .htpasswd username
    輸入密碼

    debian:/var/www# vi .htaccess

    AuthName "Auth"
    AuthType Basic
    Require valid-user
    AuthUserFile /var/www/.htpasswd

  • 修正apache2重新啟動錯誤

    debian:/etc/apache2# vi apache2.conf

    add

    ServerName localhost

    存檔後重啟apache2

    #debian:~# /etc/init.d/apache2 restart

沒有留言: