Posted on 2011/03/18 16:15
Filed Under Etc/Apache

site link : http://httpd.apache.org/docs/2.0/ko/mod/mod_file_cache.html

설명: 메모리에 정적 파일들을 캐쉬
상태: Experimental
모듈명: file_cache_module
소스파일: mod_file_cache.c

그림 파일들이 많은 사이트에 적용하면 유용할듯?

### config

Include /etc/apache2/mmap.conf
LoadModule file_cache_module /usr/lib/apache2/modules/mod_file_cache.so

>> 모듈을 로드하고 apache conf 에 아래와 같이

-----------------------------------------------

MMapFile /usr/local/apache/htdocs/index.html
or
CacheFile /usr/local/apache/htdocs/index.html
-----------------------------------------------

를 하면 되지만 다수의 파일이 있을경우엔 Include 를 적용하여 특정 파일을 지정할수도 있다.
위의 예에선 mmp.conf 라는 파일을 지정하여 해당 파일들을 list 화 했다.

list 를 하는 방법은 위 apache 사이트에도 나와 있다.

find /www/htdocs -type f -print | sed -e 's/.*/mmapfile &/' > /etc/apache2/mmap.conf
or
## 특정 확장자를 지정할경우
find /home/www/tc/attach/1/ -type f -print | grep -E ".jpg|.png|.bmp|.gif" | sed -e 's/.*/mmapfile &/' > /etc/apache2/mmap.conf

크리에이티브 커먼즈 라이센스
Creative Commons License
이올린에 북마크하기
2011/03/18 16:15 2011/03/18 16:15


Posted on 2009/04/04 23:14
Filed Under Etc/Apache






출처 : http://www.phpschool.com/gnuboard4/bbs/board.php?bo_table=tipntech&wr_id=49832&sca=%BC%B3%C4%A1%2F%BC%B3%C1%A4
작성자의 요청이 있을경우 자삭 합니다.
httpd-2.2.3, php-5.2.0 + ssl 의 설치내용입니다.
ssl설치하다 아파치의 conf파일설정이 2.2.0부터는 변경되 삽질을 좀 했습니다.
그래서 변경된 설정내용을 적었습니다.
httpd.conf 가 여러개로 나누어졌다는 것이 주내용입니다.
conf/extra 아래 여러 conf 파일이 있습니다.

기본적인 설치내용이며 ssl은 rpm으로 기본설치된 상태에서 했습니다.
php 컴파일시 xml관련 필요한 프로그램을 요구하는데,
설치하거나 옵션을 disable 해야합니다.


------------------------------------------------------------------------------------
위치 : /usr/local/src/httpd-2.2.3

./configure --prefix=/usr/local/apache2 --enable-so --enable-ssl --with-ssl=/usr
make
make install


위치 : /usr/local/src/php-5.2.0

./configure --prefix=/usr/local/php5 --with-mysql --with-apxs2=/usr/local/apache2/bin/apxs
make
make install

cp php.ini-dist /usr/local/php5/lib/php.ini



위치 : /usr/local/apache2/

vim conf/httpd.conf
DocumentRoot "/www/htdocs"
ServerAdmin ADMIN@DOMAIN.COM

# <Directory "/">
# Order deny,allow
# Deny from all
# </Directory>
# 이런설정이 디폴트여서 사용하는 디렉토리의 Allow를 해주지 않으면
# 웹에서 접근시 403에러가 난다.
# 웹에서 사용되는 가상호스트의 디렉토리에 대해 Allow from all 한다.
<Directory "/www/htdocs">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>

<Directory "/www/htdocs2">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>

AddType application/x-httpd-php .php

# 가상호스트사용을 위해서는 주석을 제거
Include conf/extra/httpd-vhosts.conf

# ssl사용을 위해서는 주석을 제거
Include conf/extra/httpd-ssl.conf



vim conf/extra/httpd-vhosts.conf
# 가상호스트설정 내용이 파일에 들어 있으니 수정해야 한다.



vim conf/extra/httpd-ssl.conf
# DocumentRoot, ServerName, SSLCertificateFile, SSLCertificateKeyFile
# 이와 관련된 내용만 수정하면 됨
# 인증관련파일은 인증서 구입한 곳에서 인증서생성 메뉴얼을 주더군요.
# 구입한 인증서 crt, key 파일 위치로 변경

DocumentRoot "/www/htdocs"
ServerAdmin ADMIN@DOMAIN.COM
SSLCertificateFile /usr/local/apache2/conf/server.crt
SSLCertificateKeyFile /usr/local/apache2/conf/server.key




실행
/usr/local/apache2/bin/apachectl start
# startssl 이 더이상 되지 않는다. 그냥 start이다.

https://WWW.DOMAIN.COM 에 들어가서 확인.







httpd.conf, httpd-vhosts.conf, httpd-ssl.conf 파일내용.


httpd.conf
----------------------------------------------------
ServerRoot "/usr/local/apache2"
Listen 80
LoadModule php5_module modules/libphp5.so
<IfModule !mpm_netware_module>
User nobody
Group nobody
</IfModule>
ServerAdmin ADMIN@DOMAIN.COM
DocumentRoot "/www/htdocs"
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
<Directory "/www/htdocs">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
<Directory "/www/htdocs2">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
<FilesMatch "^\.ht">
Order allow,deny
Deny from all
Satisfy All
</FilesMatch>
ErrorLog logs/error_log
LogLevel warn
<IfModule log_config_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
<IfModule logio_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
</IfModule>
CustomLog logs/access_log common
</IfModule>
<IfModule alias_module>
ScriptAlias /cgi-bin/ "/usr/local/apache2/cgi-bin/"
</IfModule>
<IfModule cgid_module>
</IfModule>
<Directory "/usr/local/apache2/cgi-bin">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
DefaultType text/plain
<IfModule mime_module>
TypesConfig conf/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php
</IfModule>
Include conf/extra/httpd-vhosts.conf
Include conf/extra/httpd-ssl.conf
<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>



httpd-vhosts.conf
----------------------------------------------------
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin ADMIN@DOMAIN.COM
DocumentRoot /www/htdocs
ServerName WWW.DOMAIN.COM
ServerAlias DOMAIN.COM
ErrorLog logs/www_error_log
CustomLog logs/www_access_log common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin ADMIN@DOMAIN.COM
DocumentRoot /www/htdocs2
ServerName WWW2.DOMAIN.COM
ErrorLog logs/www2_error_log
CustomLog logs/www2_access_log common
</VirtualHost>



httpd-ssl.conf
----------------------------------------------------
Listen 443
AddType application/x-x509-ca-cert .crt
AddType application/x-pkcs7-crl .crl
SSLPassPhraseDialog builtin
SSLSessionCache shmcb:/usr/local/apache2/logs/ssl_scache(512000)
SSLSessionCacheTimeout 300
SSLMutex file:/usr/local/apache2/logs/ssl_mutex
<VirtualHost *:443>
DocumentRoot "/www/htdocs"
ServerName www.DOMAIN.COM:443
ServerAdmin ADMIN@DOMAIN.COM
ErrorLog /usr/local/apache2/logs/error_log
TransferLog /usr/local/apache2/logs/access_log
SSLEngine on
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SSLCertificateFile /usr/local/apache2/conf/server.crt
SSLCertificateKeyFile /usr/local/apache2/conf/server.key
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory "/usr/local/apache2/cgi-bin">
SSLOptions +StdEnvVars
</Directory>
BrowserMatch ".*MSIE.*" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0
CustomLog /usr/local/apache2/logs/ssl_request_log \
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
</VirtualHost>

크리에이티브 커먼즈 라이센스
Creative Commons License
이올린에 북마크하기
2009/04/04 23:14 2009/04/04 23:14


Posted on 2009/04/04 23:07
Filed Under Etc/Apache

작성자의 요청이 있을경우 자삭 합니다.



GeoIP를이용한 아파지 특정 국가차단방법



1. 먼저 GeoIP C Libary를 설치
http://www.maxmind.com/app/c
./configure
make
make check
make install





2. mod_geoip2 다운로드

apache 2.x download : http://www.maxmind.com/download/geoip/api/mod_geoip2/

mod_geoip2 압축풀고 아파치에 모듈삽입
/usr/local/apache2/bin/apxs -i -a -L/usr/local/lib -I/usr/local/include -lGeoIP -c mod_geoip.c



apache 1.3.x download : http://www.maxmind.com/download/geoip/api/mod_geoip/

mod_geoip2 압축풀고 아파치에 모듈삽입
/usr/local/apache/bin/apxs -i -a -L/usr/local/lib -I/usr/local/include -lGeoIP -c mod_geoip.c

반드시 위와 같이 올려야 함.

 



3. GeoIP 데이터 다운로드
http://www.maxmind.com/download/geoip/database/
GeoLiteCity.dat.gz
압축풀고(gzip -d GeoLiteCity.dat.gz) 아파치폴더(httpd/conf)로 이동





4. httpd.conf 에 모듈활성화
LoadModule geoip_module modules/mod_geoip.so
<IfModule mod_geoip.c>
 GeoIPEnable On
 GeoIPDBFile /특정폴더/GeoLiteCity.dat
</IfModule>





5. 차단방법 예제
ex1) 211.111.13.135 아이피는 허용
httpd.conf
<Directory /차단적용디렉토리>
 SetEnvIf GEOIP_COUNTRY_CODE CN BlockCountry
 SetEnvIf GEOIP_COUNTRY_CODE US BlockCountry
 Order deny,allow
 Deny from env=BlockCountry
 Allow from 211.111.13.135
</Directory>






만약 에러가 난다면, 몇가지 유형이 있다.

1. apache2.0
/usr/local/apache2/bin/apxs -i -a -L/usr/local/lib -I/usr/local/include -lGeoIP -c mod_geoip.c
2. apache 1.3.x
/usr/local/apache/bin/apxs -i -a -L/usr/local/lib -I/usr/local/include -lGeoIP -c mod_geoip.c

이런식으로 안올리고 apxs -iac ./mod_geoip.c 형태로 올린경우

2. /etc/ld.so.conf
/usr/X11R6/lib
/usr/local/lib
/usr/local/mysql/lib
-------
이렇게 올라가 있어야 한다. 확인 후 ldconfig할것


크리에이티브 커먼즈 라이센스
Creative Commons License
이올린에 북마크하기(0) 이올린에 추천하기(0)
2009/04/04 23:07 2009/04/04 23:07


Posted on 2009/03/16 19:17
Filed Under Etc/Apache

vi /usr/local/apache/server/mpm/prefork/prefock.c
define DEFAULT_SERVER_LIMIT 1280

vi /usr/local/apache/server/mpm/worker/worker.c
define DEFAULT_SERVER_LIMIT 20

위는 profork 방식이며 아래는 mpm 방식이다.

크리에이티브 커먼즈 라이센스
Creative Commons License
이올린에 북마크하기(0) 이올린에 추천하기(0)
2009/03/16 19:17 2009/03/16 19:17


Posted on 2007/09/04 11:31
Filed Under Etc/Apache

예를 들어서

http://a.site 로 접속 하는 주소를 http://a.site:8000 으로 포워딩 하고 싶을때.
뭐... a.site 로 들어와도 프로그램의 변수로 구분을 해서 들어가도 되겠지만
특별한 경우 a.site 로 들어왔는데 포트를 달아줘야 할경우 사용하면 된다.
html의 meta 테그를 써도 되지만 Apache 차원의 포워딩을 해보자

Listen 80
Listen 8000

NameVirtualHost *:80
NameVirtualHost *:8000

<VirtualHost *:80>
    ServerAdmin email
    ServerName te.site
    Redirect    /       http://te.site:8000
</VirtualHost>
<VirtualHost *:8000>
    ServerAdmin email
    DocumentRoot        /var/www/te
    ServerName te.site
</VirtualHost>

위 처럼 셋팅을 하면 a.site 로 접속하면 a.site:8000 으로 보낸다.

크리에이티브 커먼즈 라이센스
Creative Commons License
이올린에 북마크하기(0) 이올린에 추천하기(0)
2007/09/04 11:31 2007/09/04 11:31


Posted on 2007/06/26 09:45
Filed Under Etc/Apache

출처  : http://truefeel.tistory.com/64
작성자의 요청이 있을경우 자삭 합니다.



apache 웹방화벽 modsecurity용 웹설정 툴, Remo

ModSecurity 는 아파치(apache)에서 사용하는 대표적인 웹방화벽 모듈이다. 아파치에 모듈을 설치하고, 룰(Rule) 설정을 통해 설정한 조건에 맞는 경우 차단을 할 수 있다. modsecurity 2.x 을 기준으로한 간단한 예이다.

- 웹서버명을 숨기거나 속인다.


SecServerSignature "lighttpd"


- 특정 메소드의 사용만 허용한다. (POST, GET, OPTIONS, HEAD 메소드만 허용)


SecRule REQUEST_METHOD "!^((?:(?:POS|GE)T|OPTIONS|HEAD))$" \
    "phase:1,log,auditlog,status:501,msg:'Method is not allowed by policy', severity:'2',,id:'960032',"


- 요청한 HTTP 프로토콜 버전이 1.0, 1.1이 아닐 경우 차단한다.


SecRule REQUEST_PROTOCOL "!^HTTP/(1\.[01])$" \
    "t:none, deny,log,auditlog,status:505,msg:'HTTP protocol version is not allowed by policy', severity:'2',,id:'960034',"


- GET, HEAD 메소드는 Content-Length가 0이 아닌 경우는 차단하고, POST는 Content-Length header가 없으면 차단한다.


SecRule REQUEST_METHOD "^(GET|HEAD)$" "chain,deny,log,auditlog,status:400,msg:'GET or HEAD requests with bodies', severity:'2',,id:'960011',"
SecRule REQUEST_HEADERS:Content-Length "!^0?$"

SecRule REQUEST_METHOD "^POST$" "chain,deny,log,auditlog,status:400,msg:'POST request must have a Content-Length header',,id:'960012',severity:'4'"
SecRule &REQUEST_HEADERS:Content-Length "@eq 0"


오픈소스 IDS인 snort에 기본 룰을 제공하는 것처럼 ModSecurity 에서도 modsecurity-core-rules 이름으로 룰 파일을 제공하고 있으니 참고하기 바란다. 룰에 대해서는 이만하고 원래 꺼내려한 얘기거리로 들어가자.

이런 룰 설정을 웹페이지를 통해서 할 수 있는 REMO(Rule Editor for ModSecurity) beta버전을 6월에 발표했고, Howtoforge에 Introducing Remo - An Easy Way to Secure an Insecure Online Application with ModSecurity 제목으로 REMO 다루는 방법에 대한 글이 올라왔다. 자세한 글은 Howtoforge에 글을 보시고, 간단하게 설명하면 이렇다.

REMO를 사용하기 위해서는 ruby 1.8.2이상, irb, sqlite3-ruby 환경이 필요하다. 또한 ModSecurity 모듈이 설치되지 않은 테스트나 개발 서버, 개인 PC 등에 설치해도 무관하다. 다음과 같이 실행한 후 http://서버:3000/main/index 로 접속하면 설정화면을 볼 수 있다.


wget http://remo.netnea.com/files/remo-0.2.0.tar.gz
tar xvzf remo-0.2.0.tar.gz
cd remo-0.2.0
ruby script/server




REMO화면에서 메소드와 URI등을 새로 입력한 다음, 원하는 조건을 정의한다. 그 후 'generate' 버튼을 누르면 파일로 룰셋 파일을 다운로드 받을 수 있다. 받은 룰셋을 다음과 같이 apache 설정에서 include해주면 된다.


<IfModule mod_security2.c>
    Include /파일경로/rulefile.conf
</IfModule>

REMO툴은 ModSecurity 룰 생성의 모든 것을 제공해주지는 않는다. modsecurity-core-rules 룰 파일을 보면 룰 설정이 쉽지않다는 것을 알 수 있다. 이 툴은 이런 복잡한 룰을 보고 고개를 설레설레 젓지 않도록 보조적인 역할을 하는 툴로 여기면 된다.
크리에이티브 커먼즈 라이센스
Creative Commons License
이올린에 북마크하기
2007/06/26 09:45 2007/06/26 09:45


Posted on 2007/05/18 17:28
Filed Under Etc/Apache

출처 : http://www.thesitewizard.com/archive/bandwidththeft.shtml

무단 이미지 사용 막기

.htaccess 파일에 아래의 내용을 넣으면 된다.

SetEnvIfNoCase Referer "^http://www.your-domain-name-here.com/" locally_linked=1
SetEnvIfNoCase Referer "^http://www.your-domain-name-here.com$" locally_linked=1
SetEnvIfNoCase Referer "^http://your-domain-name-here.com/" locally_linked=1
SetEnvIfNoCase Referer "^http://your-domain-name-here.com$" locally_linked=1
SetEnvIfNoCase Referer "^$" locally_linked=1
<FilesMatch "\.(gif|png|jpe?g)$">
  Order Allow,Deny
  Allow from env=locally_linked
</FilesMatch>

크리에이티브 커먼즈 라이센스
Creative Commons License
이올린에 북마크하기
2007/05/18 17:28 2007/05/18 17:28


Posted on 2007/05/03 23:16
Filed Under Etc/Apache

htpasswd와 htaccess를 이용하여 웹 인증 페이지를 만들어보자

우선 인증을 걸고자 하는 디렉토리로 이동하여

ex)cd  /usr/local/apache/htdocs/webfolder

.htaccess 파일을 만든다.

ex) vi .htaccess

아래의 내용을 입력한다.

AuthName WebLog ## 인증창의 이름
AuthType Basic ## 인증 타입 보통 Basic를 사용
AuthUserFile /usr/local/apache/htdocs/weblog/.htpasswd
## htpasswd를 이용하여 생성되는 .htpasswd의 위치
AuthGroupFile /dev/null ## 그룹으로 인증할경우는 그룹 파일을 아닐경우 null 을 넣는다.
<Limit GET POST>
require valid-user ## 인증된 사용자만 접속 허용 하기
</Limit>

이제... 사용자와 패스워드를 만든다.

사용법

Usage:
        htpasswd [-cmdpsD] passwordfile username
        htpasswd -b[cmdpsD] passwordfile username password


        htpasswd -n[mdps] username
        htpasswd -nb[mdps] username password
 -c  Create a new file.
 -n  Don't update file; display results on stdout.
 -m  Force MD5 encryption of the password.
 -d  Force CRYPT encryption of the password (default).
 -p  Do not encrypt the password (plaintext).
 -s  Force SHA encryption of the password.
 -b  Use the password from the command line rather than prompting for it.
 -D  Delete the specified user.
On Windows, NetWare and TPF systems the '-m' flag is used by default.
On all other systems, the '-p' flag will probably not work.


ex) htpasswd -c .htpasswd x2x (엔터)
를 누르고 패스워드 입력

이렇게 하고... 해당 페이지를 접속해 보자...^^

확인 되었으면... 끝.

크리에이티브 커먼즈 라이센스
Creative Commons License
이올린에 북마크하기(0) 이올린에 추천하기(0)
2007/05/03 23:16 2007/05/03 23:16


Posted on 2007/04/20 11:42
Filed Under Etc/Apache

Apache 2.x

httpd.conf 파일을 열어서

<Directory "해당 경로">
Oprion FollowSymLinks
AllowOverride None

## 링크 허용 부분
SerEnvIfNoCase Referer ^http://domain.com goout
SerEnvIfNoCase Referer ^http://domain.net goout

#이미지가 새창을 열경우 엑박(X)으로 보이는걸 방지하기 위한 레퍼럴이 존재하지 않는 요청
SerEnvIfNoCase Referer ^$ goout

# 파일 확장자 지정하기
<Files ~ "\.(gif|jpe?g|png|bmp|zip|tar|rar|alz|a00|ace|txt|mp3|mpe?g|wav|asf|wma|wmv|swf|exe)$">
Order deny,allow
deny from all
allow from env=goout

## 무단 링크시 띄워줄 에러
ErrorDocument 403 http:// 경고를 보여줄 Img 나 html
</Files>
</Directory>



참고 : http://www.neosky.info 
크리에이티브 커먼즈 라이센스
Creative Commons License
이올린에 북마크하기(0) 이올린에 추천하기(0)
2007/04/20 11:42 2007/04/20 11:42


Posted on 2007/04/20 10:16
Filed Under Etc/Apache

--------------------------------------------------------------------


제  목 : 아파치 설정 활용 예(서비스 제한측면)
작성자 : 좋은진호(truefeel, http://coffeenix.net/ )
작성일 : 2003.2~
정리일 : 2005.1.28(금)


아파치 웹서버의 활용에 있어, 보다나은 보안 설정 방법 몇 가지를 소개한다.


특정 Agent가 자꾸 사이트에 들어와서 긁어간다든지,
이미지 파일을 외부에서 링크하지 못하도록 한다든지,
특정 IP에서는 인증없이, 그 이외 IP에서는 아파치 인증을 통해서만 페이지를 보게하는
등의 응용적인 측면에서 방법들이다.
이 방법들은 제가 사용하고 있는 몇가지 방법을 정리하는 의미에서 적은 것이다.


1. 특정 브라우저의 접속을 차단


--------------------------------------------------------------------
SetEnvIfNoCase User-Agent "^Microsoft URL Control" dont_want


<Directory /usr/local/apache/htdocs>
   <Limit GET POST>
        Order Allow,Deny
        Allow from all
        Deny  from env=dont_want
   </Limit>
</Directory>
[/quote]
--------------------------------------------------------------------


----------------------------------------------
SetEnvIfNoCase User-Agent "^Wget" bad_bot
SetEnvIfNoCase User-Agent "^EmailSiphon" bad_bot
SetEnvIfNoCase User-Agent "^EmailWolf" bad_bot


The 'SetEnvIfNoCase' simply sets an enviornment (SetEnv) variable called
'bad_bot' If (SetEnvIf) the 'User-Agent' string contains Wget, EmailSiphon, or
EmailWolf, regardless of case (SetEnvIfNoCase). In english, anytime a browser
with a name containing 'wget, emailsiphon, or emailwolf' accesses our website,
we set a variable called 'bad_bot'. We'd also want to add a line for the
User-Agent string of any other Spidert we want to deny.


Now we tell Apache which directories to block the Spiderts from with the
<Directory> directive:


<Directory "/home/evolt/public_html/users/">
        Order Allow,Deny
        Allow from all
        Deny from env=bad_bot
</Directory>


2.  다른 곳에서 images를 link하지 못하도록


1) 디렉토리를 제한하는 방법


referer 체크를 통해 외부에서 /images 이하디렉토리의 파일을 link하지 못하도록 한다.
이를테면 truefeel.kr 이라는 사이트가 있을 때
truefeel.kr내에 있는 동영상을 이 도메인에서는 링크할 수 있지만
외부 사이트에서는 이 동영상을 링크해도 권한이 없도록 할 수 있다.


--------------------------------------------------------------------
SetEnvIf Referer "^http://localhost/"  local_referal
SetEnvIf Referer "^http://127.0.0.1/"  local_referal
SetEnvIf Referer "^http://홈페이지명/" local_referal
SetEnvIf Referer "^$"                  local_referal


<Directory /usr/local/apache/htdocs/images>
   Order Deny,Allow
   Deny  from all
   Allow from env=local_referal
</Directory>
--------------------------------------------------------------------


2) 이미지 파일 확장자로 제한하는 방법 (서비스 페이지가 ????.truefeel.kr 일 때)
                                                                                   
--------------------------------------------------------------------
SetEnvIfNoCase Referer "^http://localhost/"        local_referal
SetEnvIf       Referer "^http://127.0.0.1/"        local_referal
SetEnvIfNoCase Referer "^http://(.*).truefeel.kr/" local_referal
SetEnvIfNoCase Referer "^http://truefeel.kr/"      local_referal
SetEnvIfNoCase Referer "^$"                        local_referal
                                                                                   
<Files ~ "\.(gif|jpg|jpeg|png|bmp)$">
   Order deny,allow
   Deny  from all
   Allow from env=local_referal
</Files>
--------------------------------------------------------------------


3. 특정 IP에서만 접근 가능하게


너무나도 흔한 방법이긴 한데, 개인적으로 저에게 이런 부분을 물어보시는 분이 많았다.
아래의 예는 /usr/local/apache/htdocs 디렉토리를 211.111.222.0/24 대역에서만 접근가능한 설정이다.


--------------------------------------------------------------------
<Directory "/usr/local/apache/htdocs">
    Options FollowSymLinks MultiViews
    AllowOverride AuthConfig
    Order deny,allow
    Deny from all
    Allow from 211.111.222.0/255.255.255.0
</Directory>
--------------------------------------------------------------------


반대로 아래와 같이 하면 지정한 IP대역에서만 접근할 수 없다.


--------------------------------------------------------------------
... 생략 ...
    Order allow,deny
    Allow from all
    Deny from 211.111.222.0/255.255.255.0
... 생략 ...
--------------------------------------------------------------------


4. 특정페이지를 인증된 사용자만 볼 수 있는 아파치 인증 설정


이번 글은 5번의 인증 설정을 알기 전에 아파치 인증에 대해 모르는 분을 위해 적은 것으로
아파치 인증이 무엇인지 안다면 5번으로 바로 넘어가기 바란다.


아파치에서는 특정 페이지를 접근할 때 ID와 비밀번호를 알아야만 접근하도록 설정할 수 있다.
다음 예를 보자.


--------------------------------------------------------------------
<Directory "/home/truefeel/public_html">
            Options FollowSymLinks MultiViews
            AllowOverride AuthConfig
</Directory>
--------------------------------------------------------------------


위 처럼 AllowOverride AuthConfig 설정을 하면 ~truefeel/public_html 디렉토리에 인증 과정을
거치는 기본 설정은 된 것이다.
만약 ~truefeel/public_html/manager/ 아래의 디렉토리에 인증을 걸려고 한다면 그 디렉토리에
다음과 같은 형식의 .htaccess 파일을 생성한다.


[ ~truefee/public_html/manger/.htaccess 파일 내용 ]
--------------------------------------------------------------------
AuthType Basic
AuthName User   <-- "User" 는 인증창에 표시될 메시지 중의 하나일 뿐 신경쓸 필요 없다.
AuthUserFile /home/truefeel/manage/.htpasswd
AuthGroupFile /dev/null
<Limit GET POST>
require valid-user
</Limit>
--------------------------------------------------------------------


.htpasswd 파일에 ID/PW를 생성해두면 해당페이지 인증을 할 수 있게 된다.


5. 특정 IP는 인증없이, 그 이외는 아파치 인증 거치도록


아래의 설정은 위의 4번 글을 읽었다면 뭔가 종합적인 설정을 한 것 처럼 보일 것이다.


--------------------------------------------------------------------
<Location />
    AuthType Basic
    AuthName User
    AuthUserFile /home/truefeel/manage/.htpasswd
    AuthGroupFile /dev/null


    require valid-user
    order deny,allow
    deny  from all
    allow from 211.111.222.0/255.255.255.0
    Satisfy any
</Location>
--------------------------------------------------------------------


위의 설정은
- 211.111.222.0/24 IP 대역에 있는 접속자는 인증없이 통과하고,
- 그 이외의 IP 대역에서 접속하면 인증을 거쳐야하는 설정이다.
이 설정은 Satisfy any 지시자를 통해서 이뤄진다. IP가 맞거나 ID/PW가 맞으면 되는 것이다. (OR)


만약 Satisfy all 이라고 적었다면
- IP대역이 211.111.222.0/24 이면서
- 인증까지 모두 통과 해야
해당 페이지에 접근이 가능하다. (AND)


6. 업로드 디렉토리의 .php파일은 text처럼 인식하기


php나 cgi 등으로 파일 업로드 가능하도록 구현된 경우 .php나 .html 등의 파일을 업로드할 수
있는 실수를 범할 수 있다.


이런 실수를 하더라도 지정한 업로드 디렉토리에 있는 .php나 .html 파일을 php프로그램으로
인식하지 않고 일반 텍스트 파일로 판단하도록 설정하여 보다 안전한 웹페이지 구성이 가능하다.
다음은 /upload/ 와 /files/ 디렉토리 아래의 php파일은 일반 텍스트로 인식하라는 설정이다.


--------------------------------------------------------------------
<Directory ~ "/usr/local/apache/htdocs/(upload|files)">
        RemoveType .html .php
</Directory>
--------------------------------------------------------------------


위에서 ~ 기호는 디렉토리 경로에 정규 표현식을 사용하겠다는 의미로 (upload|files) 부분을
정규 표현식으로 인식한다. 따라서 htdocs/ 이하의 upload 디렉토리와 files 디렉토리를 의미한다.


단순히 /home/truefeel/public_html/data 디렉토리라면
<Directory "/home/truefeel/public_html/data"> 와 같이 설정하면 된다.


7. 참고 자료


* Apache Directives
  http://httpd.apache.org/docs/mod/directives.html
* Apache Authentication and Access Control
  http://www.apache.kr.net/documents/authplus-story.html

크리에이티브 커먼즈 라이센스
Creative Commons License
이올린에 북마크하기(0) 이올린에 추천하기(0)
2007/04/20 10:16 2007/04/20 10:16


About

by 삐꾸강아쥐

Counter

· Total
: 138036
· Today
: 12
· Yesterday
: 155
블로그코리아에 블UP하기