2019년 12월 17일 화요일

FTP로만 작업 가능한 웹사이트에 .htaccess 와 .htpasswd로 기본인증(Basic Authentication)을 설정해야했습니다.

FTP로만 작업 가능한 웹사이트에 .htaccess 와 .htpasswd로 기본인증(Basic Authentication)을 설정해야했습니다.
그 작업의 기록입니다.

.htpasswd파일의 작성
서버의 명령을 실행할 수 없으니 .htapasswd파일의 내용을 별도 작성해서 업로드하기로 합니다.
ID:PW(MD5해쉬)
"htpasswd generator"로 검색하면 많은 사이트들이 검색됩니다.


Htpasswd Generator – Create htpasswd - Htaccess Tools
Htpasswd Generator – Create htpasswd Use the htpasswd generator to create passwords for htpasswd files. Just enter username and password and an entry for a htpasswd file is generated. You can use the htaccces Authentication generator to create a htaccess f
www.htaccesstools.com
생성된 내용을 .htpasswd파일로 저장합니다.

.htaccess파일의 작성(혹은 업데이트)

<Files ~ "^\.(htaccess|htpasswd)$">
Deny from all
</Files>
AuthType Basic
AuthUserFile /.htpasswd의 절대경로/
AuthName "Please enter your ID and password"
Require valid-user
.htpasswd의 절대경로을 알아내야합니다.

php의 getcwd()함수를 이용합니다.

<?php
   echo getcwd();
?>
"/var/www/vhosts/xxxxxxx"를 알아냈습니다.

<Files ~ "^\.(htaccess|htpasswd)$">
Deny from all
</Files>
AuthType Basic
AuthUserFile /var/www/vhosts/xxxxxxx/.htpasswd
AuthName "Please enter your ID and password"
Require valid-user
.htaccess파일을 새로 생성하거나, 기존 파일의 맨 위에 붙여넣습니다.

서버에 업로드
/.htaccess
/.htpasswd
파일을 업로드합니다.

잘 작동합니다.

내용을 변경한 경우에는 브라우저의 캐쉬를 삭제한 후 접속하면 바로 업데이트한 내용의 확인이 가능합니다.


댓글 없음:

댓글 쓰기

1、2、QWER! in OSAKA (大阪 2025/4/10(木) Yogibo META VALLEY)

https://www.creativeman.co.jp/event/qwer-osaka/ QWER - CREATIVEMAN PRODUCTIONS 主催:LIVET 企画:ソニー・ミュージックソリューションズ 招聘:クリエイティブマンプロダクション 制作協力:クリエイテ...