TIL_5

-·2021년 2월 3일
0

TIL

목록 보기
6/15

프록시, VPN, 토르

프록시?

사용자의 인터넷 트래픽을 목표 서버까지 전달하는 가상 “통로”라 할 수 있다.

중계기 느낌?

이때, 사용자의 IP와 활동은 프록시 서버 자체에 기록 된다 (기록 되지 않을 수도 있다).

하지만 프록시는 통로역할을 할뿐 데이터를 암호화하지는 않는다.

VPN?

단순한 “통로”라기 보다는 정교한 프라이버시와 보안 역량을 갖춘 암호화된 터널로 사용자의 IP 주소를 감추는 단순한 작업 그 이상을 해낸다.

토르?

작동 원리는 본질적으로 대역폭과 IP 주소를 공유하는 사용자의 완전히 암호화된 망사형 네트워크를 형성을 통해 가능하며, 로컬 컴퓨터 동력을 전반적으로 암호화된 네트워크를 유지할 수 있도록 기여한다.

토르 프로토콜을 사용해 로컬 토르 클라이언트를 설치해 모든 트래픽을 암호화하고 익명화 할 수 있다. 혹은, 토르 브라우저 소프트웨어로 웹 검색을 할 수도 있다.

캡처

이런식으로 기본적으로 3곳을 중계한다.

NGINX 설정

기본적으로 nginx.conf라는 설정파일이 있다.

Listen Port

기본적으로 80번 포트로 잡혀있지만 변경하고 싶으면 이 부분을 변경해주면된다.

server {
	listen       80;
	......
}
Document Root

root를 확인. default는 html 디렉토리 입니다.

html 대신에 원하는 Document Root Directory를 적으면 됩니다.

location / {
	root   html;
	...
}
초기 페이지 설정

index를 확인합니다. default는 index.html 입니다.

만일 index에 지정된 파일들이 존재하지 않는 경우 403 Forbidden 오류를 만나게 됩니다.

location / {
	...
	index  index.html index.htm;
}
proxy_pass 설정

특정 확장자 요청을 넘기는 설정을 추가해 봅니다. 즉, Nginx 뒷 단에 Tomcat 등의 WAS 가 존재하는 경우이며, 확장자 기반으로 요청 처리를 분리하는 것입니다. 물론 Nginx-JBoss 연동도 가능합니다.

아래 예는 *.do 에 대하여 http://localhost:8080 으로 넘기는 것입니다.

// *.do 에 대하여 http://localhost:8080 으로
location ~ \.do$ {
	proxy_pass  http://localhost:8080;
}
// 그냥 http://localhost:8080 으로
location / {
	proxy_pass  http://localhost:8080;
}
Sub Domain 설정
    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   /home/nginx;
            index  index.html index.htm;
        }
        ......
    }
// nginx1.appsroot.com sub Domain추가
    server {
        listen       80;
        server_name  nginx1.appsroot.com;

        location / {
            root   /home/nginx1;
            index  index.html index.htm;
        }
    }
// nginx2.appsroot.com sub Domain추가
    server {
        listen       80;
        server_name  nginx2.appsroot.com;

        location / {
            root   /home/nginx2;
            index  index.html index.htm;
        }
    }
// 이렇게도 가능 default 값을 사용하는 경우는 명시적으로 설정하지 않아도 무관합니다. listen의 80, index의 index.html 등등
    server {
        server_name  nginx2.appsroot.com;

        location / {
            root   /home/nginx2;
        }
    }

server block이 2개 추가되었고 각각 nginx1.appsroot.com (/home/nginx1), nginx2.appsroot.com (/home/nginx2)의 역할을 담당하고 있습니다.

access log 설정

access_log를 확인합니다. default 는 logs/access.log 입니다. 앞서 설명한 Sub Domain (Virtual Host) 로 분리되어 있어도 별도로 access log 설정을 하지 않으면 하나의 access.log 파일로 쌓입니다.

    // default
    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;
        ...
	}
	// 나누기
	server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        access_log  logs/host.access.log;
        ......
    }    

    server {
        #listen       80;
        server_name  nginx1.appsroot.com;

        access_log  logs/nginx1.access.log;
        ......
    }

    server {
        #listen       80;
        server_name  nginx2.appsroot.com;

        access_log  logs/nginx2.access.log;
        ......
    } 
NGINX에서 HTTPS가 HTTP로 변경되는 이슈

일부 상황에서 HTTPS 프로토콜에서 HTTP 프로토콜로 변경되어버리는 현상

캡처

이렇게! 오류가 난다

nignx설정파일에 추가를 해주자

error_page 497 https://$host:listenport$request_uri;

497에러가 "a regular request has been sent to the HTTPS port."

HTTP 요청이 HTTPS 포트로 요청되었다는 것으로 이럴경우 뒤의 https://$host:listenport$request_uri 경로로 redirect시켜준다는 것입니다.

profile
거북이는 오늘도 걷는다

0개의 댓글