Nginx 편집하기

이동: 둘러보기, 검색

경고: 로그인하지 않았습니다. 편집을 하면 IP 주소가 공개되게 됩니다. 로그인하거나 계정을 생성하면 편집자가 사용자 이름으로 기록되고, 다른 장점도 있습니다.

편집을 되돌릴 수 있습니다. 이 편집을 되돌리려면 아래의 바뀐 내용을 확인한 후 저장해주세요.
최신판 당신의 편집
1번째 줄: 1번째 줄:
 
== Admin Guide ==
 
== Admin Guide ==
 +
 +
=== Security Controls ===
 +
 +
==== Restricting Access with HTTP Basic Authentication ====
 +
https://docs.nginx.com/nginx/admin-guide/security-controls/configuring-http-basic-authentication/
 +
 +
===== Creating a Password File =====
 +
Apache와 Basic 인증으로 접근 제한하기
 +
 +
[[htpasswd]] 명령으로 만들 수 있다.
  
 
=== Web Server ===
 
=== Web Server ===
  
 
==== NGINX Reverse Proxy (리버스 프록시) ====
 
==== NGINX Reverse Proxy (리버스 프록시) ====
https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/
 
  
 
===== Passing a Request to a Proxied Server =====
 
===== Passing a Request to a Proxied Server =====
20번째 줄: 29번째 줄:
 
     proxy_pass http://localhost:8000;
 
     proxy_pass http://localhost:8000;
 
}
 
}
</syntaxhighlight>proxy_set_header 지시어를 사용하여 프록시된 서버로 전달되는 헤더 필드를 변경하거나 제거할 수 있습니다. 이 지시어는 location, server, http 블록 등에서 지정할 수 있습니다. 위 예제에서 [[HTTP#Host|Host]] 필드는  $proxy_host변수로 설정되었다.  <syntaxhighlight lang="nginx">
+
</syntaxhighlight>nginx는 [[HTTP#Host|Host]][[HTTP#Connection|Connection]]을 재정의하고 empty string인 헤더 필드를 제거합니다. Host는 $proxy_host변수로 설정되고, Connection은 close로 설정된다.  
location /some/path/ {
 
    proxy_set_header Accept-Encoding "";
 
    proxy_pass http://localhost:8000;
 
}
 
 
 
</syntaxhighlight>위 예제에서 Accept-Encoding 필드가 프록시된 서버로 전달되는 것을 방지하기 위하여 빈 문자열로 설정했다.
 
 
 
[[Nginx Proxy Manager]]를 사용할 수 있다.  
 
 
 
=== Security Controls ===
 
 
 
==== Restricting Access with HTTP Basic Authentication ====
 
https://docs.nginx.com/nginx/admin-guide/security-controls/configuring-http-basic-authentication/
 
 
 
===== Creating a Password File =====
 
Apache와 Basic 인증으로 접근 제한하기
 
 
 
[[htpasswd]] 명령으로 만들 수 있다.  
 
  
 
== http core module ==
 
== http core module ==
https://nginx.org/en/docs/http/ngx_http_core_module.html
 
  
 
=== location ===
 
=== location ===
81번째 줄: 71번째 줄:
  
 
“/documents/1.jpg”를 요청하면 설정E가 매칭될 것이다.
 
“/documents/1.jpg”를 요청하면 설정E가 매칭될 것이다.
 
=== 변수 ===
 
 
==== $scheme ====
 
request scheme, “http” or “https”
 
 
==== $host ====
 
클라이언트 요청 헤더의 Host 필드의 값
 
 
== Nginx Http Proxy module ==
 
 
=== proxy_set_header ===
 
https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_set_header
 
 
[[HTTP#X-Forwarded-For .28XFF.29|X-Forwarded-For]], [[HTTP#X-Forwarded-Proto .28XFP.29|X-Forwarded-Proto]], [[HTTP#X-Forwarded-Host .28XFH.29|X-Forwarded-Host]] 을 주로 설정하는데, HttpContext.Connection.RemoteIpAddress는 X-Forwarded-For 헤더 값을 사용하여 설정됩니다. HttpContext.Request.Scheme은 X-Forwarded-Proto 헤더 값을 사용하여 설정됩니다. HttpContext.Request.Host는 X-Forwarded-Host 헤더 값을 사용하여 설정됩니다.<syntaxhighlight lang="nginx">
 
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 
proxy_set_header X-Forwarded-Proto $scheme;
 
proxy_set_header X-Forwarded-Host $host;
 
</syntaxhighlight>
 
 
=== 변수 ===
 
 
==== proxy_add_x_forwarded_for ====
 
<syntaxhighlight lang="nginx">
 
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 
</syntaxhighlight>만약 클라이언트에서 request header에 [[HTTP#X-Forwarded-For .28XFF.29|X-Forwarded-For]]가 없다면 $proxy_add_x_forwarded_for는 $remote_addr 와 동일한데 실제 서버에서 보자면 요청하는 것은 프록시 서버이기 때문에 $remote_addr은 프록시 서버의 아이피가 되므로 실제 클라이언트 아이피를 서버가 알 수 있도록 하기 위해서 위의 설정이 필요하다.
 
 
== [[CORS]] ==
 
<syntaxhighlight lang="nginx">
 
location /api {
 
        # for OPTIONS return these headers and HTTP 200 status
 
        if ($request_method = OPTIONS ) {
 
            add_header Allow "OPTIONS";
 
            add_header 'Access-Control-Allow-Methods' 'GET, POST, DELETE, PATCH, OPTIONS';
 
            add_header Access-Control-Allow-Headers 'Content-Type, Authorization';
 
            add_header Access-Control-Allow-Origin "https://[your allow hostname]";
 
            return 204;
 
        }
 
        proxy_pass http://[your-hostname]/api;
 
}
 
</syntaxhighlight>[[HTTP#OPTIONS|OPTIONS]] 메서드에 대한 응답을 추가할 수 있다.
 
  
 
== 보안설정 ==
 
== 보안설정 ==
128번째 줄: 77번째 줄:
 
<nowiki>#</nowiki>/etc/nginx/nginx.conf
 
<nowiki>#</nowiki>/etc/nginx/nginx.conf
  
=== HSTS ===
 
<syntaxhighlight lang="nginx">
 
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload";
 
</syntaxhighlight>
 
 
=== 서버 버전 숨기기 등 ===
 
=== 서버 버전 숨기기 등 ===
 
<syntaxhighlight lang="nginx">
 
<syntaxhighlight lang="nginx">
237번째 줄: 182번째 줄:
 
===SSL routines:tls_process_client_hello:version too low===
 
===SSL routines:tls_process_client_hello:version too low===
 
IE 6.0등 브라우저 버전이 낮은 경우에 발생한 보안에러이다.
 
IE 6.0등 브라우저 버전이 낮은 경우에 발생한 보안에러이다.
 
== 외부링크 ==
 
변수 인덱스: http://nginx.org/en/docs/varindex.html
 
 
[[분류:Web server]]
 
[[분류:Web server]]

wwiki에서의 모든 기여는 다른 기여자가 편집, 수정, 삭제할 수 있다는 점을 유의해 주세요. 만약 여기에 동의하지 않는다면, 문서를 저장하지 말아 주세요.
또한, 직접 작성했거나 퍼블릭 도메인과 같은 자유 문서에서 가져왔다는 것을 보증해야 합니다 (자세한 사항은 Wwiki:저작권 문서를 보세요). 저작권이 있는 내용을 허가 없이 저장하지 마세요!

취소 편집 도움말 (새 창에서 열림)