2014년 2월 18일 화요일

Apache RewriteEngine Rule 문법.

[출처] [Apache] Rewrite모듈|작성자 참좋은날

Rewrite 는 Client 의 url 요청을 웹서버에 요청하기전에, 원하는 url로 다시써서(변형해서) 서버에 요청한다.
[참고 : http://httpd.apache.org/docs/current/mod/mod_rewrite.html]

 └>Rewrite는 Directory , VirtualHost 지시자 및  .htaccess파일에서 동작한다.


1. RewriteEngine
rewrite 모듈은 기본적으로 Off 되어 있으며, 사용하고자 하는 경우 On으로 활성화 해주어야 한다.
문법: RewriteEngine [On|Off]
<Virtual Host>를 설정해서 사용하고 있는 경우 각 Virtual Host마다 RewriteEngine을 On 시켜줘야 한다.

2. RewriteCondRewriteCond에서 설정한 패턴과 일치하는 경우에 다음에 오는 RewriteRule들을 실행한다.
문법: RewriteCond (String) (Pattern/Instruction) [flag]
(String) : 입력된 문자열(서버변수 사용가능)이 Pattern(펄정규식)과 일치하거나 Instruction(명령어)와 일치하는 경우 결과를 RewriteRule로 넘긴다.

3. RewriteRule특정 패턴에 해당되는 URL을 지정된 규칙에 따라 변환한다.
문법: RewriteRule (Pattern) (Substitution) [flag]
* 사용가능한 서버변수
HTTP Headers connection & request server internals date & time specials
HTTP_USER_AGENT
HTTP_REFERER
HTTP_COOKIE
HTTP_FORWARDED
HTTP_HOST  : 요청된 URL 전체
HTTP_PROXY_CONNECTION
HTTP_ACCEPT  REMOTE_ADDR
REMOTE_HOST
REMOTE_PORT
REMOTE_USER
REMOTE_IDENT
REMOTE_METHOD
SCRIPT_FILENAME
PATH_INFO
QUERY_STRING
AUTH_TYPE  DOCUMENT_ROOT
SERVER_ADMIN
SERVER_NAME
SERVER_ADDR
SERVER_PORT
SERVER_PROTOCOL
SERVER_SOFTWARE  TIME_YEAR
TIME_MON
TIME_DAY
TIME_HOUR
TIME_MIN
TIME_SEC
TIME_WDAY
TIME  API_VERSION
THE_REQUEST
REQUEST_URI : 요청된 URL중 도메인을 뺀 부분
REQUEST_FILENAME
IS_SUBREQ
HTTPS

* 명령어(instruction)-d 디렉토리를 의미
-f 파일을 의미
-l 심볼릭링크를 의미
-d not을 의미(!-d,!-f,!-l)

* 플래그(flag) [참고 : http://httpd.apache.org/docs/current/rewrite/flags.html ]
F | forbidden 요청페이지를 403 에러 페이지로 redirect 시킴
G | gone 요청페이지를 410 에러 페이지로 redirect 시킴
L | last 다음의 Rule을 무시하고 종료
C | chain 결과를 다음 Rule의 input값으로 넘김
N 새로운 Rule이 시작
R 무조건 Redirection 시킴
NC 대소문자를 구별하지 않음
OR OR
QSA Cond의 내용을 지난결과에 덧붙임
NE 출력문자에 특수문자가 HexCode가 있는경우
PT | passthrough : 강제적으로 결과 URI를 기존의 입력된 URL의 URI로 사용한다. 마치 Alias 나 Redirect 처럼 사용된다.
 예)
 Alias /icons /usr/local/apache/icons
 RewriteRule /pics/(.+)\.jpg /icons/$1.gif [PT]
 PT 플래그의 생략하면 Alias가 무시되어진다. 그 결과 'File not found' 라는 에러가 뿌려지게 된다.
 PT 플래그는 L플러그를 의미한다: Rewriting 은 다음 프로세싱 단계로 넘어가기 위해 정지 된다.
 PT 플래그는 <Directory>섹션 혹은 .htaccess 파일에서 동작한다.
$1,$2 ... RewriteCond 나 RewriteRule 에 string 값으로 (.*) 같은 변형 될수 있는 값들을 지정했을때 사용자로 부터 입력된 값이 $1 , $2 ... 이런식으로 변수가 된다.

RewriteBase URL-path
기본 디렉토리를 설정, 이후 지정되는 경로는 기본 디렉토리를 기반으로 설정된다. 이 옵션은 오직 .htaccess 파일안에서만 동작한다.

RewriteLogLevel  [0~9]
Rewrite실행 로그의 레벨을 지정한다. 9가 가장 Detail 하게 볼 수 있다.

RewriteLog [로그남길 경로]
Rewrite모듈이 실행되는 과정과 결과를 로그로 남긴다.(※ RewriteRule 설정시 로그를 확인해 가며 설정 하는게 유리하다)




2014년 2월 13일 목요일

Rsync 비밀번호 없이 실행하기 (Exec Rsync without Password)


Crontab Rsync without Password

1. local 서버에서 ssh-keygen 을 실행하여 "id_rsa.pub" 파일을 작성한다.
(by running "ssh-copy-id", sent the file - "id_rsa.pub" to the Remote Server.)

2. 작성된 "id_rsa.pub" 파일을 "ssh-copy-id" 를 실행하여 Remote Server 로 전송한다.
( by running ssh-keygen, make the file "id_rsa.pub" to be written on local server)

3. Rsync를 실행하여 패스워드 없이 접속되는 것을 확인한다.
(confirm to execute Rsync ...)

- 로컬 서버와 Remote 서버에 ssh-keygen 으로 만든 같은 비밀번호가 저장되어 있으므로, IP가 변경이 되어도 패스워드 없이 계속 접속할 수 있다.


예제(example)

> ssh-keygen
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
c9:b8:27:a2:bd:xx:xx:xx:xx:34:a5:ef:89:f1:ec:ec root@www6.gettyimageskorea.com
The key's randomart image is:
+--[ RSA 2048]----+
| |
| |
| . |
| xxxxx |
| xxxxxx |
| . o . |
| xxxxxx |
| xxxxxxxx . |
| . +xxxxx+. |
+-----------------+

> ssh-copy-id -i ~/.ssh/id_rsa.pub xxx.xxx.xxx.xxx
root@xxx.xxx.xxx.xxx's password:

Now try logging into the machine, with "ssh '121.78.196.150'", and check in:

.ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

done.
---------------------------------------------------------------------------