아파치 Proxy balancer 를 이용한 로드밸런싱



Apache 모듈 중에 mod_proxy_balancer 를 이용해서 로드밸런싱이 가능하다.


아래 예제는 /test 라는 경로가 지정되었지만 루트라도 관계가 없다.


loadfactor 는 가중치이다. 이 수치를 이용해서 특정 서버로 부하를 더 분산할 수도 있다.


   <IfModule mod_proxy_balancer.c>

        ProxyPass               /test       balancer://mycluster

        ProxyPassReverse        /test       balancer://mycluster

        <Proxy balancer://mycluster>

            BalancerMember http://www1.example.com/test loadfactor=25

            BalancerMember http://www2.example.com/test loadfactor=25

            BalancerMember http://www3.example.com/test loadfactor=25

            BalancerMember http://www4.example.com/test loadfactor=25

            ProxySet lbmethod=byrequests

        </Proxy>

    </IfModule>


단순 컨텐츠는 효과가 없을 듯 하고 프로그래밍 같은 경우에는 효과가 있을 것 같다.


정적인 컨텐츠는 mod_cache 를 활용하는게 더 효과적일 것 같다.


아니면 앞단의 장비에서 로드밸런싱을 하는게 낫지 않을까 싶다.


블로그 이미지

영은파더♥

가상서버호스팅 VPS 리눅스 서버관리 윈도우 IT

,

SSH 인증키 원격지 서버에 올려서 암호입력 없이 접속하기



백업 또는 서버관리를 위해서 SSH 사용이 아주 빈번하다. RSYNC 또는 SCP, SFTP 같은 유틸로 파일을 백업하고자 할 때,


CRON에 백업스크립트를 등록하여 자동백업 하고자 할 때 비밀번호 입력 없이 파일 업로드가 가능하다면 아주 편리할 것이다.


아래는 백업서버가 1대(conoha) 운영서버 여러대(linode, vultr, etc) 있고 운영서버의 인증키를 백업서버(원격지)에 올리는 방법이다.



▶ Linode SSH 인증키 생성 및 업로드


[root@linode ~]# ssh-keygen -t rsa

Generating public/private rsa key pair.

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:

f9:99:30:0e:8d:cc:a1:44:c6:ac:19:6e:67:19:04:5a root@linode.ivps.kr

The key's randomart image is:

+--[ RSA 2048]----+

|  E=+            |

| o.o+            |

|.. +.o.          |

|  =.++ + .       |

| . o. = S        |

|       o + o     |

|        . +      |

|                 |

|                 |

+-----------------+


[root@linode ~]# cat ./.ssh/id_rsa.pub | ssh -p10022 root@conoha.ivps.kr "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"

The authenticity of host '[conoha.ivps.kr]:10022 ([133.130.126.29]:10022)' can't be established.

ECDSA key fingerprint is d1:33:b1:93:a0:7c:5b:7e:3b:e1:5b:2b:13:8a:27:01.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added '[conoha.ivps.kr]:10022,[133.130.126.29]:10022' (ECDSA) to the list of known hosts.

root@conoha.ivps.kr's password:



▶ Linode SSH 인증키 생성 및 업로드


[root@vultr ~]# ssh-keygen -t rsa

Generating public/private rsa key pair.

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:

d1:22:15:0c:4e:d5:95:19:fd:c6:c8:4f:8b:5b:f8:01 root@vultr.ivps.kr

The key's randomart image is:

+--[ RSA 2048]----+

|      o++o .o=   |

|     o .... o .  |

|      o o .  . + |

|       . o   Eo =|

|        S     ++.|

|             o +.|

|              + .|

|             . . |

|                 |

+-----------------+


[root@vultr ~]# cat ./.ssh/id_rsa.pub | ssh -p10022 root@conoha.ivps.kr "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"

The authenticity of host '[conoha.ivps.kr]:10022 ([133.130.126.29]:10022)' can't be established.

ECDSA key fingerprint is d1:33:b1:93:a0:7c:5b:7e:3b:e1:5b:2b:13:8a:27:01.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added '[conoha.ivps.kr]:10022,[133.130.126.29]:10022' (ECDSA) to the list of known hosts.

root@conoha.ivps.kr's password:



▶ Conoha 에서 인증키가 정상적으로 복사되었는지 확인


[root@conoha ~]# cat ~/.ssh/authorized_keys

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC3P6CFMztEsGJzLjGhoGNomDKAQ5CgnVW5eV79zRWTGdamxHtJLZS1sq5lCk4oFAslhD4fStQguH4TKVrhFhwczK+mIX7iaycUVJshH2QB4Zce4rM+7loacU1WKOjE1LK4twWggH8LsJHkwRqBaZi/9mXYbBsUpsnR1PvBxZ5ub+61jqujD13jgwMS9tlVSLsM9VFrn/+bMEt8bAwSeVCPlY2QroeL7euu/H6CwW4NYGEPXOEnu6k9W5WKSeBo+WjTsLvip/UziJ6+jjs2z+VGeg2iyOXBG6onXAnfa9vaY+gqQ6X5ZL2/5TFP9T1nYNlask2W6FlQhe09OpDDaVA1 root@linode.ivps.kr

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDIacorFIiihlSc8fDOrZNab79w7STxi6ubNOAn+BsnBBKawMlWWEb6gzQTC0BTcZUQpm/s3LFQgQGdu5cfdVi+DfmicOQo9N+bjNLv/NHfoCt0yEWmlWDx2iew37Lv1BzrV/w1T2xssx7KVCrRg+NmcUbP0yPegtGsvjR17vpCafam7jxN2TRxo3uk7ah9z8budaKACMeOpF1JhEpMSahmHvweyUXNIpN3dnBnfZIUqwFFh+RnOY3rR2L2W9c0bc6KQSGpl0BavqeGrSNhYNwVYn2tcCGcDCePqrT4mFkG+QPxhpZmNNeNrlRS5NDB9FgBbVCUMuFtI7aD4qW7itI1 root@vultr.ivps.kr


~/.ssh/authorized_keys 파일에 두 서버의 SSH 인증키가 합쳐져 있다.



▶ SSH 접속 테스트


[root@vultr ~]# ssh -p10022 root@conoha.ivps.kr

Last login: Mon May 30 13:06:06 2016 from 107.191.53.38

[root@conoha ~]# exit

logout

Connection to conoha.ivps.kr closed.

[root@vultr ~]#


[root@linode ~]# ssh -p10022 root@conoha.ivps.kr

Last login: Mon May 30 13:08:51 2016 from 107.191.53.38

[root@conoha ~]# exit

logout

Connection to conoha.ivps.kr closed.

[root@linode ~]#


이제 두 서버 모두 암호 입력없이 로그인이 된다.


scp 예제보기 https://ivps.tistory.com/77


sftp 예제보기 https://ivps.tistory.com/78



블로그 이미지

영은파더♥

가상서버호스팅 VPS 리눅스 서버관리 윈도우 IT

,

리눅스 sftp 암호입력 없이 사용하는 방법



sftp 뿐만 아니라 rsync, ssh, scp 등 ssh 로그인을 사용하는 유틸은 모두 동일하다.


인증키를 원격지서버에 올리는 방법은 scp 를 설명하는 게시글 https://ivps.tistory.com/77 여기에도 언급되어 있지만 다시 설명하자면 아래와 같다.


ssh-keygen 으로 인증키를 만들어서 원격지 서버로 업로드하면 된다.


▶ ssh 인증키 생성


[root@conoha ~]# ssh-keygen -t rsa

Generating public/private rsa key pair.

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:

62:1b:92:d1:58:21:4a:b1:36:86:62:1f:71:90:e0:ec root@conoha.ivps.kr

The key's randomart image is:

+--[ RSA 2048]----+

| .+++.o.         |

|oo +o=           |

|o+*.o .          |

|+o...o           |

| E .o + S        |

|     o +         |

|      .          |

|                 |

|                 |

+-----------------+


[root@conoha ~]# scp -P10022 ./.ssh/id_rsa.pub root@vultr.ivps.kr:~/.ssh/authorized_keys

root@vultr.ivps.kr's password:

id_rsa.pub                                    100%  398     0.4KB/s   00:00


위에서는 scp 로 업로드를 하였지만 sftp 로 올려도 된다.


[root@conoha ~]# sftp -P10022 root@vultr.ivps.kr

root@vultr.ivps.kr's password:

Connected to vultr.ivps.kr.

sftp> put ./.ssh/id_rsa.pub ./.ssh/authorized_keys

Uploading ./.ssh/id_rsa.pub to /root/./.ssh/authorized_keys

./.ssh/id_rsa.pub                             100%  393     0.4KB/s   00:00

sftp> ls .ssh

.ssh/authorized_keys

sftp> bye


위 처럼 /root/.ssh 디렉토리에 authorized_keys 이름으로 인증키를 업로드한 뒤 부터는 비밀번호를 묻지않고 접속이 가능해진다.

 ( 여러개 다수의 서버라면 여기를 참고 https://ivps.tistory.com/79 )



▶ sftp 옵션설명 ( 아래의 옵션은 scp 랑 같다. )


-C 전송시 파일을 압축해서 전송한다.

-l 전송속도 옵션이다. 단위는 Kbit/s

-P 포트지정 옵션이다. 22번 포트는 생략하여도 된다.

-p 원본 파일과 시간을 동일하게 복사한다.

-q 전송진행 상태를 안보여준다.

-r 하위 디렉토리까지 같이 복사하다.

-v 디버깅메시지를 보여준다. 그러나 너무 분잡하다.


그리고 sftp 접속 후의 ls, get, put 등의 명령어는 ftp 명령어랑 똑같다.


[root@conoha ~]# sftp -P10022 -Cpr root@vultr.ivps.kr

Connected to vultr.ivps.kr.

sftp> help

Available commands:

bye                                Quit sftp

cd path                            Change remote directory to 'path'

chgrp grp path                     Change group of file 'path' to 'grp'

chmod mode path                    Change permissions of file 'path' to 'mode'

chown own path                     Change owner of file 'path' to 'own'

df [-hi] [path]                    Display statistics for current directory or

                                   filesystem containing 'path'

exit                               Quit sftp

get [-Ppr] remote [local]          Download file

reget remote [local]            Resume download file

help                               Display this help text

lcd path                           Change local directory to 'path'

lls [ls-options [path]]            Display local directory listing

lmkdir path                        Create local directory

ln [-s] oldpath newpath            Link remote file (-s for symlink)

lpwd                               Print local working directory

ls [-1afhlnrSt] [path]             Display remote directory listing

lumask umask                       Set local umask to 'umask'

mkdir path                         Create remote directory

progress                           Toggle display of progress meter

put [-Ppr] local [remote]          Upload file

pwd                                Display remote working directory

quit                               Quit sftp

rename oldpath newpath             Rename remote file

rm path                            Delete remote file

rmdir path                         Remove remote directory

symlink oldpath newpath            Symlink remote file

version                            Show SFTP version

!command                           Execute 'command' in local shell

!                                  Escape to local shell

?                                  Synonym for help

sftp> !


아래는 배치파일로 업로드 및 다운로드 하는 방법이다.


[root@conoha ~]# dd if=/dev/zero of=./100M.bin bs=100M count=1

1+0 records in

1+0 records out

104857600 bytes (105 MB) copied, 0.169097 s, 620 MB/s

[root@conoha ~]# echo "put 100M.bin" > sftp.batch

[root@conoha ~]# echo "get 100M.bin" >> sftp.batch

[root@conoha ~]# sftp -P10022 -Cpr -b sftp.batch root@vultr.ivps.kr

sftp> put 100M.bin

sftp> get 100M.bin


옵션 -b 패치파일 형태이다.


블로그 이미지

영은파더♥

가상서버호스팅 VPS 리눅스 서버관리 윈도우 IT

,

리눅스 서버간 scp로 파일 복사하기



리눅스 서버간에 파일을 업로드하는 방법은 ftp, rsync 도 있겠지만 ssh 를 이용하는 scp (secure copy) 도 있다.


먼저 ssh-keygen 으로 인증키를 만들어서 원격지 서버에 넣어 놓아야 scp 로 파일 복사시 암호를 더 이상 묻지 않는다.


rsync 와 거의 유사해서 백업용으로 사용이 가능하다.



▶ 인증키 만들기 (ssh-keygen -t rsa or dsa)


[root@conoha ~]# ssh-keygen -t rsa

Generating public/private rsa key pair.

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:

62:1b:92:d1:58:21:4a:b1:36:86:62:1f:71:90:e0:ec root@conoha.ivps.kr

The key's randomart image is:

+--[ RSA 2048]----+

| .+++.o.         |

|oo +o=           |

|o+*.o .          |

|+o...o           |

| E .o + S        |

|     o +         |

|      .          |

|                 |

|                 |

+-----------------+


[root@conoha ~]# ssh-keygen -t dsa

Generating public/private dsa key pair.

Enter file in which to save the key (/root/.ssh/id_dsa):

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /root/.ssh/id_dsa.

Your public key has been saved in /root/.ssh/id_dsa.pub.

The key fingerprint is:

4c:15:b1:5c:00:cc:0a:0d:60:24:0d:8e:75:94:81:fa root@conoha.ivps.kr

The key's randomart image is:

+--[ DSA 1024]----+

|o+=+== o..=+.    |

|o+o.o . oo o     |

|.o   . .. o      |

|.     .o         |

| .      S        |

|  E              |

|                 |

|                 |

|                 |

+-----------------+


암호화 방식의 차이니깐 둘 중에 마음에 드는 것을 선택하면 된다.



이제 인증키를 원격서버에 업로드 하자. ( 여러개 다수의 서버라면 여기를 참고 https://ivps.tistory.com/79 )


[root@conoha ~]# scp ./.ssh/id_rsa.pub root@vultr.ivps.kr:~/.ssh/authorized_keys

ssh: connect to host vultr.ivps.kr port 22: Connection refused

lost connection

You have new mail in /var/spool/mail/root


ssh 포트가 맞지 않아서 실패하였다.


포트 옵션을 주고 다시 실행


[root@conoha ~]# scp -P10022 ./.ssh/id_rsa.pub root@vultr.ivps.kr:~/.ssh/authorized_keys

root@vultr.ivps.kr's password:

id_rsa.pub                                    100%  398     0.4KB/s   00:00


[root@conoha ~]# scp -P10022 ./.ssh/id_rsa.pub root@vultr.ivps.kr:~/.ssh/authorized_keys

id_rsa.pub                                    100%  398     0.4KB/s   00:00


첫번째는 인증키가 원격지 서버에 아직 없으므로 패스워드를 물어본다.

두번재는 인증키가 이미 올라간 상태라서 비밀번호를 묻지 않고 바로 복사가 되었다.



▶ scp 옵션


-C 전송시 파일을 압축해서 전송한다.

-l 전송속도 옵션이다. 단위는 Kbit/s

-P 포트지정 옵션이다. 22번 포트는 생략하여도 된다.

-p 원본 파일과 시간을 동일하게 복사한다.

-q 전송진행 상태를 안보여준다.

-r 하위 디렉토리까지 같이 복사하다.

-v 디버깅메시지를 보여준다. 그러나 너무 분잡하다.



▶ scp 복사 예제


테스트용 디렉토리와 100MByte 파일 생성

[root@conoha ~]# mkdir -p ./testdir/subdir

[root@conoha ~]# dd if=/dev/zero of=./testdir/subdir/100M.bin bs=100M count=1

1+0 records in

1+0 records out

104857600 bytes (105 MB) copied, 0.227941 s, 460 MB/s


30Mbps 속도로 원격지 서버에 testdir 디렉토리를 전송 (속도가 제어되어서 전송되었다.)

[root@conoha ~]# scp -P10022 -l30000 -pr ./testdir/ root@vultr.ivps.kr:~/testdir/

100M.bin                                      100%  100MB   3.7MB/s   00:27


속도제한 없이 원격지 서버에 전송 (160Mbps 속도가 나온다.)

[root@conoha ~]# scp -P10022 -pr ./testdir/ root@vultr.ivps.kr:~/testdir/

100M.bin                                      100%  100MB  20.0MB/s   00:05


압축해서 원격지 서버에 전송 (800Mbps 속도가 나왔다. 더미파일이라서 압축효과가 있다.)

[root@conoha ~]# scp -P10022 -Cpr ./testdir root@vultr.ivps.kr:~/

100M.bin                                      100%  100MB 100.0MB/s   00:01


이번엔 원서버에 원본 디렉토리를 지우고

[root@conoha ~]# rm -rf testdir


원격지 서버의 testdir 디렉토리를 다운로드

[root@conoha ~]# scp -P10022 -Cpr root@vultr.ivps.kr:~/testdir ~/

100M.bin                                      100%  100MB  50.0MB/s   00:02

[root@conoha ~]# scp -P10022 -pr root@vultr.ivps.kr:~/testdir ~/

100M.bin                                      100%  100MB  20.0MB/s   00:05

[root@conoha ~]# ls -l ~/testdir/subdir/

합계 102400

-rw-r--r-- 1 root root 104857600  5월 27 11:53 100M.bin


rsync 의 --delete 옵션이 scp 에는 없는거 빼고는 별 차이가 없는 것 같다.


물론 rsync 는 한번 복사 이후에는 변경된 파일만 백업이 이뤄지는 아주 큰 매력이 있긴하다.



블로그 이미지

영은파더♥

가상서버호스팅 VPS 리눅스 서버관리 윈도우 IT

,

CentOS 7.x 호스트네임 변경하기



기존 방식대로 /etc/hostname 파일을 수정해도 되고 hostnamectl 유틸을 사용해도 된다.



▶ 호스트네임 확인


[root@conoha bin]# hostnamectl

   Static hostname: localhost

         Icon name: computer-vm

           Chassis: vm

        Machine ID: ce592a37a02b45f78d729b0b2e24d5cf

           Boot ID: 62082661e9f840a59c2ebf6789b7a56e

    Virtualization: kvm

  Operating System: CentOS Linux 7 (Core)

       CPE OS Name: cpe:/o:centos:centos:7

            Kernel: Linux 3.10.0-327.10.1.el7.x86_64

      Architecture: x86-64


▶ 호스트네임 변경


[root@conoha bin]# hostnamectl set-hostname www.example.com



변경이 되었는지 확인해보자.


[root@conoha bin]# hostnamectl

   Static hostname: www.example.com

         Icon name: computer-vm

           Chassis: vm

        Machine ID: ce592a37a02b45f78d729b0b2e24d5cf

           Boot ID: 62082661e9f840a59c2ebf6789b7a56e

    Virtualization: kvm

  Operating System: CentOS Linux 7 (Core)

       CPE OS Name: cpe:/o:centos:centos:7

            Kernel: Linux 3.10.0-327.10.1.el7.x86_64

      Architecture: x86-64


[root@conoha bin]# cat /etc/hostname

www.example.com


[root@conoha bin]# hostname

www.example.com



블로그 이미지

영은파더♥

가상서버호스팅 VPS 리눅스 서버관리 윈도우 IT

,

리눅스 아파치 서버가 살아있는지 체크하는 쉘스크립트



ping 을 막아 놓은 경우에 확인해 볼 수 있는 방법중 하나이다.


서버를 체크해서 이전 상태와 다를 경우 이메일로 결과를 전송하도록 작성해보았다.


우선 웹서버에 robots.txt 파일을 하나 생성해주자.


User-agent: *

Disallow: /


이 파일이 다운로드 받아지는지 체크하면 된다.


# touch /usr/local/bin/server-check.sh

# chmod 700 /usr/local/bin/server-check.sh

# vi /usr/local/bin/server-check.sh

#!/bin/sh


CHECK_DOMAINS="

http://www.example.com

http://www1.example.com

http://www2.example.com

http://www3.example.com

"

CHECK_FILE="robots.txt"

SAVE_PATH="/root"

TO_EMAIL="webmaster@example.com"


for DOMAIN in $CHECK_DOMAINS

do

CHECK_URL="$DOMAIN/$CHECK_FILE"

SUBJECT="$CHECK_URL 서버체크 결과"

LAST_STATE="$SAVE_PATH/$(echo $DOMAIN | base64).state"


wget -O $SAVE_PATH/$CHECK_FILE $CHECK_URL


if [ -f $LAST_STATE ] ; then

LAST_LIFE=`cat $LAST_STATE`

else

LAST_LIFE="init"

fi


if [ -s /root/$CHECK_FILE ] ; then

CURR_LIFE="true"

else

CURR_LIFE="false"

fi

echo $CURR_LIFE > $LAST_STATE


echo "LAST_LIFE : $LAST_LIFE, CURR_LIFE : $CURR_LIFE"

if [ "$LAST_LIFE" != "$CURR_LIFE" ] ; then

echo "Server status : no same"

if [ "$CURR_LIFE" == "false" ] ; then

EMAIL_MSG="$CHECK_URL 웹서비스가 반응이 없습니다."

else

EMAIL_MSG="$CHECK_URL 웹서비스가 정상입니다."

fi

echo "$EMAIL_MSG" | /bin/mail -s "$SUBJECT" "$TO_EMAIL"

else

echo "Server status : same"

fi

done


위 코드를 응용해서 크론에 등록해서 체크를 하면 된다.


[root@conoha cron.d]# echo "*/5 * * * * root /usr/local/bin/server-check.sh" > /etc/cron.d/server-check

[root@conoha cron.d]# cat /etc/cron.d/server-check

*/5 * * * * root /usr/local/bin/server-check.sh

[root@conoha cron.d]# chmod 600 /etc/cron.d/server-check

[root@conoha cron.d]# ls -l /etc/cron.d
-rw-r--r--  1 root root 128  4월  1 00:09 0hourly
-rw-r--r--. 1 root root 108  9월 19  2015 raid-check
-rw-------  1 root root  44  5월 27 10:36 server-check
-rw-------. 1 root root 235  3월  6  2015 sysstat



블로그 이미지

영은파더♥

가상서버호스팅 VPS 리눅스 서버관리 윈도우 IT

,

아파치 IP 로 접속시 차단 방법



웹주소를 IP로 홈페이지에 접근시 차단해주는 방법이다.


<VirtualHost *:80>

    ServerName 192.168.1.100

    <Location />

        Order deny,allow

        Deny from all

    </Location>

</VirtualHost>


192.168.1.100 이 부분에 자신의 서버IP를 적어주면 된다.

아파치 재시작


IP 로 홈페이지를 열어보면 아래와 같은 메시지를 볼 수 있을 것이다.


Forbidden

You don't have permission to access / on this server.


블로그 이미지

영은파더♥

가상서버호스팅 VPS 리눅스 서버관리 윈도우 IT

,

리눅스 아파치 VirtualHost 설정 방법



/etc/httpd/conf/httpd.conf 파일에


Include conf/example.conf 을 추가해서 아래의 파일을 /etc/httpd/conf/example.conf 파일로 저장을 하거나


/etc/httpd/conf.d/example.conf 파일로 저장을 하면 된다.


가상호스트를 여러개를 만들어야 하는 경우라면 두번째 방법이 편하다.


그리고 80 포트 외에 다른 포트를 사용하고 싶다면


Listen 8080

NameVirtualHost *:80

NameVirtualHost *:8080

<VirtualHost *:80 *:8080>


이렇게 적어주면 된다.


NameVirtualHost *:80


<VirtualHost *:80>

    ServerName www.example.com

    DocumentRoot /home/example/www

    SetEnvIfNoCase Request_URI "\.(png|gif|jpg|js|css|ico)$" NO_LOG

    SetEnvIf Remote_Addr "^::1$" NO_LOG

    ErrorLog logs/www.example.com-error_log

    LogFormat "%V %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" vcommon

    CustomLog logs/www.example.com-access_log vcommon env=!NO_LOG

    <IfModule mod_ruid2.c>

        RDocumentChRoot / /home/example/www

        RMode          config

        RUidGid        example example

    </IfModule>

</VirtualHost>


mod_ruid2 부분은 사용자계정의 권한을 갖게 해주는 모듈이다.


설치 방법은 https://ivps.tistory.com/72 여기를 참고하자.


블로그 이미지

영은파더♥

가상서버호스팅 VPS 리눅스 서버관리 윈도우 IT

,

CentOS 7.x 아파치 mod_ruid2 설치 및 설정방법



CentOS 7.x 버전에서는 이전 방식과 달리 mod_ruid2 를 yum 으로 install 할 수가 있다.


mod_ruid2 모듈 설치 (권한 설정 모듈)


# yum -y install mod_ruid2



RDocumentChRoot 부분 설정이 DocumentRoot 와 달라서 조금 헤메었다.


NameVirtualHost *:80


<VirtualHost *:80>

    ServerName www.example.com

    #DocumentRoot /home/example/www

    <IfModule mod_ruid2.c>

        RDocumentChRoot / /home/example/www

        RMode          config

        RUidGid        example example

    </IfModule>

</VirtualHost>


아파치 재시작하고 확인을 해보자.


파일이나 디렉토리를 생성해보거나 echo exec('whoami'); 를 호출해서 찍어보면 된다.



조금 더 자세한 설정 방법은 /etc/httpd/conf.d/mod_ruid2.conf 파일을 참고하면 된다.



블로그 이미지

영은파더♥

가상서버호스팅 VPS 리눅스 서버관리 윈도우 IT

,

아파치 .htaccess Rewrite URL 리디렉트 처리



특정 파일 또는 이미지 호출시 다른 URL 로 리디렉션 하고 싶을때 Rewrite 모듈을 활용하면 된다.

아니면 특정IP 차단 등에 응용이 가능하다.


.htaccess 파일에 아래코드 추가


RewriteEngine On

RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]

RewriteCond %{REMOTE_ADDR} ^192.168.100.123$

RewriteCond %{SERVER_PORT} !^8080$

RewriteCond %{REQUEST_URI} ^/directory/(.+).(jpg|gif|png)$ [NC]

RewriteCond %{HTTP_USER_AGENT} (Android) [NC]

RewriteRule ^(.*)/directory/(.+)$ http://www.example.com:8080/directory/$2 [R=301,L]


RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]

VirtualHost 운영중이라면 여러개의 호스트주소에서 www.example.com 인 경우 ( [NC] 는 대소문자 구별을 안함)


RewriteCond %{REMOTE_ADDR} ^192.168.100.123$

특정 클라이언트 IP 만 조건 처리 가능


RewriteCond %{SERVER_PORT} !^8080$

특정 포트 ! 은 반대의 의미 ( ^8080$ : 8080 포트인 경우, !^8080$ : 8080 포트가 아닐 경우 )


RewriteCond %{REQUEST_URI} ^/directory/(.+).(jpg|gif|png)$ [NC]

특정 디렉토리 아래의 확장자 jpg, gif, png 인 경우


RewriteCond %{HTTP_USER_AGENT} (Android) [NC]

유저에이전트가 Android 인 경우


RewriteRule ^(.*)/directory/(.+)$ http://www.example.com:8080/directory/$2 [R=301,L]

www.example.com:8080 으로 리디렉션 처리
도메인주소를 제외한 뒤쪽 주소가 동일하다면 http://www.example.com:8080%{REQUEST_URI} 이렇게도 처리가 가능하다.

위의 예제를 참고해서 원하는 리디렉트 처리가 가능하다.


.htaccess 에서 RewriteEngine 이 안 된다면 https://ivps.tistory.com/97 여기를 참고하자.


블로그 이미지

영은파더♥

가상서버호스팅 VPS 리눅스 서버관리 윈도우 IT

,