(1)현황:
며칠 전부터 특정 IP들이 장시간 개인홈페이지를 access하고 있으며 일일 traffic양을 일찍 소진시켜 홈페이지가 뜨지 않는 현상 발생.
문제의 ip들은 54.36.150.86, 54.36.150.67, 54.36.148.55, 54.36.148.108, 54.36.149.32, 등등.
프랑스에서 여러 개의 ip들로 장시간 개인홈페이지의 traffic을 점유하는 것은 정상적이 아니므로 막기로 결정함.
(2)해결:
.htaccess 파일에 비정상적인 traffic을 발생시키는 ip 혹은 사이트 주소(제로보드의 "관리" tool을 사용하여 "리퍼러통계"를 사용하니 비정상적으로 특정 사이트,즉
http://twks.dothome.co.kr 으로부터 개인홈페이지 접근이 많음이 발견. )를 등록하면 된다.deny from 54.36.148
deny from 54.36.150 으로 등록하였다가 54.36.149도 발견되어 아예 프랑스로부터 들어오는 걸 모두 막기 위해 deny from 54.36 로 수정하였다.
.htaccess 파일은 숨겨진 파일이므로 (알)FTP의 옵션 메뉴/환경설정/일반/"숨겨진 파일 보여줌"에 check표시후 확인 클릭해야 모습을 드러낸다.
.htaccess 파일이 있는 위치는 홈페이지의 index.html이 있는 폴더에 있다.
(remote server 창의)" .htaccess" 파일에 커서를 위치하고 마우스 우측을 누르면 나타나는 메뉴창 내의 "수정(J)" 를 클릭.
아래(1)의 (1)처럼 메모장(notepad)이 나타나면 아래(1)의 (2)처럼 문제의 ip와 문제의 사이트 주소를 추가등록후 file/save.
고로 (알)FTP의 창이 뜨는데 ".htaccess 파일을 전송하시겠습니까?"에 대해 "예" 클릭. 고로 해결됨.
그런데 " .htaccess" 파일을 여는 프로그램은 기본적으로 연결되어 있는 메모장(notepad) 보다는, textpad를 본인은 잘 사용하고 있기 때문에 textpad에 연결하였다.
메모장(notepad)가 아니라, 아래의 내용으로 textpad로 보여지는 것이 수정하기도 더 편하기 때문.
.htaccess 파일을 클릭하면 textpad가 뜨도록 하려면 다음과 같이 설정해주면 된다.
즉 (알)FTP의 옵션 메뉴/환경설정/고급/수정시 연결할 프로그램 내에서 "확장자"는 ".htaccess" 를 입력하고, "연결 프로그램"에는 폴더를 찾아가는 아이콘을 클릭하여 "textpad.exe"를 찾아내어 선택한 후, "추가"버튼 클릭하면 된다.
(3)참조:
.htaccess 파일은 특정 폴더(및 그 하부의 폴더들까지 모두)에 접근을 제한하는 기능을 한다. 특정 홈페이지에 대한 접근을 제한하는 것이 아니라, .htaccess 파일이 위치하고 있는 폴더(디렉토리)와 그 하부 폴더(sub-directory)전체에 대한 특정 ip및 특정 홈페이지으로부터의 접근을 제한하는 것이다. 그리고 .htpasswd 파일을 이용하면, id와 password를 설정 가능하다.
.htaccess 는 서버에서 지원을 해야 사용이 가능한데 cafe24, dothome은 지원한다. 지원하지 않는 데도 많다고 하니 지원여부는 호스팅 업체에게 문의해보시기를.
-아래(1)-
(1).htaccess 파일 (수정 전)
SetEnvIfNoCase remote_addr 66.249.77.61 go_out
SetEnvIfNoCase remote_addr 66.249.73.* go_out
SetEnvIfNoCase remote_addr 66.249.74.62 go_out
SetEnvIfNoCase remote_addr 66.249.77.180 go_out
SetEnvIfNoCase remote_addr 61.247.204.36 go_out
SetEnvIfNoCase remote_addr 61.247.204.37 go_out
SetEnvIfNoCase remote_addr 61.247.204.38 go_out
SetEnvIfNoCase remote_addr 61.247.204.39 go_out
SetEnvIfNoCase remote_addr 66.249.72.170 go_out
SetEnvIfNoCase remote_addr 27.101.192.205 go_out
SetEnvIfNoCase remote_addr 66.249.72.170 go_out
SetEnvIfNoCase remote_addr 66.249.72. go_out
SetEnvIfNoCase remote_addr 66.249.77. go_out
SetEnvIfNoCase remote_addr 66.249.74. go_out
SetEnvIfNoCase remote_addr 61.247.204. go_out
SetEnvIfNoCase remote_addr 27.101.192.241 go_out
SetEnvIfNoCase remote_addr 180.76.5.196 go_out
SetEnvIfNoCase remote_addr 180.76.5.* go_out
SetEnvIfNoCase remote_addr 180.76.6.* go_out
SetEnvIfNoCase remote_addr 27.101.192.208 go_out
SetEnvIfNoCase remote_addr 27.101.192.* go_out
Order Allow,Deny
Allow from all
Deny from env=go_out
(66.249.77.61, 66.249.73.* 등등을 막느라 오래전에 " .htaccess" 파일을 만들어 그 속에 coding해 넣은 내용이다.)
(2).htaccess 파일 (수정 후)
SetEnvIfNoCase remote_addr 66.249.77.61 go_out
SetEnvIfNoCase remote_addr 66.249.73.* go_out
SetEnvIfNoCase remote_addr 66.249.74.62 go_out
SetEnvIfNoCase remote_addr 66.249.77.180 go_out
SetEnvIfNoCase remote_addr 61.247.204.36 go_out
SetEnvIfNoCase remote_addr 61.247.204.37 go_out
SetEnvIfNoCase remote_addr 61.247.204.38 go_out
SetEnvIfNoCase remote_addr 61.247.204.39 go_out
SetEnvIfNoCase remote_addr 66.249.72.170 go_out
SetEnvIfNoCase remote_addr 27.101.192.205 go_out
SetEnvIfNoCase remote_addr 66.249.72.170 go_out
SetEnvIfNoCase remote_addr 66.249.72. go_out
SetEnvIfNoCase remote_addr 66.249.77. go_out
SetEnvIfNoCase remote_addr 66.249.74. go_out
SetEnvIfNoCase remote_addr 61.247.204. go_out
SetEnvIfNoCase remote_addr 27.101.192.241 go_out
SetEnvIfNoCase remote_addr 180.76.5.196 go_out
SetEnvIfNoCase remote_addr 180.76.5.* go_out
SetEnvIfNoCase remote_addr 180.76.6.* go_out
SetEnvIfNoCase remote_addr 27.101.192.208 go_out
SetEnvIfNoCase remote_addr 27.101.192.* go_out
<Files *>
Order Allow,Deny
Allow from all
deny from 54.36.148
deny from 54.36.150
deny from 54.36
deny from .*example\.com.*
deny from .*twks\.dothome.co.kr.*
Deny from env=go_out
</Files>
View the following article for instructions on how to create an .htaccess file on your web server:
If the file already exists, view the following articles for instructions on how to update it (depending on if you're using an FTP client or SSH):
Once the file has been created, you can add the code examples below to it.
Denying access to specific file extensions
The following code forces any file ending in .inc to throw a 404 Forbidden error when visited:
<Files ~ "\.inc$">
Order Allow,Deny
Deny from All
</Files>
File names beginning with a dot are considered "hidden" by UNIX. Usually, you don't want to serve them to visitors.
DreamHost already disallows retrieving '.htaccess' and '.htpasswd', but you can recursively deny all access to all hidden files by placing the following into a top-level .htaccess:
Denying access to a directory listing
If you don't have an index file in your directory, all of your files are listed in a directory list for anyone to view. The following code forces this directory listing to throw a 404 Forbidden error instead when visited:
If you wish to block access to files in a directory during a specific time of day, then you can do so by adding the following code to an .htaccess file:
RewriteEngine On
# If the hour is 16 (4 PM)
RewriteCond %{TIME_HOUR} ^16$
# Then deny all access
RewriteRule ^.*$ - [F,L]
If someone visits the directory anytime between 4:00 – 4:59 pm, a 500 Internal Server error is thrown. You can also specify multiple hours as well:
RewriteEngine On
# Multiple hour blocks
# If the hour is 4 PM or 5 PM or 8 AM
RewriteCond %{TIME_HOUR} ^16|17|08$
# Then deny all access
RewriteRule ^.*$ - [F,L]
If you have a directory named 'blah' that you want to block, but it can occur anywhere in your directory tree, use the following:
RewriteEngine On
RewriteRule (^|/)blah(/|$) - [F]
If you have problems with certain visitors to your website, you can easily ban them. There are two different ways to ban visitors:
- using their IP address, or
- the domain name from which they are visiting.
Here's an example that denies a user by their IP address:
deny from 173.236.241.100
When the user tries to connect to your site from that specific IP, they see a 403 Forbidden page instead. If you want to block an entire block of IPs, just leave the last octet off. For example:
This denies access from anyone using an IP in the range from 173.236.241.0 all the way up to 173.236.241.255.
The following link is a useful online tool that automatically generates an IP range for you:
If you need to deny access to your site to everyone while still allowing yourself or another specific IP address to visit it, you can use something like this:
order deny,allow
deny from all
allow from <YOUR_IP_ADDRESS>
This denies access from anyone connecting to your site from www.example.com. If someone clicks on a link at example.com that redirects to your site, they then see a 403 Forbidden error:
SetEnvIfNoCase Referer "example.com" bad_referer
Order Allow,Deny
Allow from ALL
Deny from env=bad_referer
This example throws a 500 Internal Server Error for anyone linking from example.com:
RewriteEngine on
RewriteCond %{HTTP_REFERER} example\.com [NC,OR]
RewriteRule .* - [F]
The following example redirects any visitor connecting from example.com to google.com:
RewriteEngine On
RewriteCond %{HTTP_REFERER} ^http://example.com/
RewriteRule /* http://www.google.com [R,L]
https://www.techrepublic.com/blog/web-designer/quick-tip-how-to-limit-access-to-a-web-directory-by-ip-address/
Quick tip: How to limit access to a web directory by IP address