Apache2 - Directory Alias and Allow From

ทำ Alias ใช้ในกรณีที่ directory นั้นๆ ไม่ได้อยู่ใน document root ของ web server เช่น
อยากให้ url http://www.kmitl.ac.th/bankster  แต่ directory bankster ไม่ได้อยู่ที่ document root
ของ www.kmitl.ac.th อาจจะอยู่ที่อื่นอย่างเช่น /home/bankster/public_html
สามารถทำการ set เป็นลักษณะของ Alias ได้ที่ /etc/apache2/sites-enabled/www.kmitl.ac.th

โดยเพิ่ม  Alias /bankster “/home/bankster/public_html”    ไว้ภายใน tag <VirtualHost> … </VirtualHost>

แล้วทำการ set option สำหรับ directory /home/bankster/public_html ดังนี้

<Directory /home/bankster/public_html>
Options FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
สังเกตุว่า ไม่อนุญาตให้ทำการ Index Directory เพราะไม่ได้ set
Options Indexs FollowSymLinks MultiViews

ข้อสังเกตุสุดท้าย คือ
option allow from all
คือ สามารถเรียกดู directory นี้ได้จากทุกที่ แต่ถ้าเราอยากให้เรียกได้เฉพาะที่ล่ะ
ก็ set เป็นแบบนี้
<Directory /home/bankster/public_html>
Options FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from 161.246.0.0/255.255.0.0
</Directory>

จากตัวอย่าง เป็นการอนุญาตให้มีการเรียก directory นี้จาก client ที่มี IP Address อยู่ใน network
161.246.0.0/16 ถ้าเรียกใช้ directory นี้จาก IP Address อื่นๆ นอกเหนือจากที่กำหนดไว้
Web Server จะ แสดงข้อความ

Forbidden

You don’t have permission to access /bankster/ on this server.

จบแล้วครับ

Tags: , , ,

This entry was posted on Friday, February 6th, 2009 at 10:14 pm and is filed under sysadmin. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply