2191
all application on unix knowledges by golfreeze / Re: set mod rewrite ใน file .htaccess
« on: มกราคม 23, 2011, 12:19:18 am »
ต้องการจำกัด user ที่จะเข้าถึงไดเรกทอรี conf
สำหรับ apache ที่ใช้ทดสอบนั้น สามารถสร้างแฟ้มคอนฟิกแยกจาก httpd.conf ได้โดยใส่ในไดเรกทอรี conf.d
ให้สร้างแฟ้ม /etc/httpd/conf.d/my.conf โดยเพิ่มบรรทัดเหล่านี้
<Directory "/var/www/cgi-bin/conf">
Options ExecCGI FollowSymLinks
AllowOverride None
Options None
AuthType Basic
AuthName "Please enter our server's User Account"
AuthUserFile /var/www/users/local_users
Require user user1 user2
Order Allow,Deny
Allow from all
Satisfy all
</Directory>
สร้าง user ดังนี้
ครั้งแรก ใส่ -c เพื่อสร้างไฟล์ ด้วย
htpasswd -c /var/www/users/local_users user1
รอให้ใส่ password ของ user1 ดังนี้
New password:
Re-type new password:
Adding password for user user1
ครั้งต่อไปไม่ต้องใส่ -c
htpasswd /var/www/users/local_users user2
เสร็จแล้วให้ restart httpd ดังนี้
service httpd restart
สำหรับ apache ที่ใช้ทดสอบนั้น สามารถสร้างแฟ้มคอนฟิกแยกจาก httpd.conf ได้โดยใส่ในไดเรกทอรี conf.d
ให้สร้างแฟ้ม /etc/httpd/conf.d/my.conf โดยเพิ่มบรรทัดเหล่านี้
<Directory "/var/www/cgi-bin/conf">
Options ExecCGI FollowSymLinks
AllowOverride None
Options None
AuthType Basic
AuthName "Please enter our server's User Account"
AuthUserFile /var/www/users/local_users
Require user user1 user2
Order Allow,Deny
Allow from all
Satisfy all
</Directory>
สร้าง user ดังนี้
ครั้งแรก ใส่ -c เพื่อสร้างไฟล์ ด้วย
htpasswd -c /var/www/users/local_users user1
รอให้ใส่ password ของ user1 ดังนี้
New password:
Re-type new password:
Adding password for user user1
ครั้งต่อไปไม่ต้องใส่ -c
htpasswd /var/www/users/local_users user2
เสร็จแล้วให้ restart httpd ดังนี้
service httpd restart