주 메뉴 열기

wwiki β

바뀜

Nginx

1,014 바이트 추가됨, 2023년 11월 4일 (토) 01:01
에러
proxy_pass http://localhost:8000;
}
</syntaxhighlight>proxy_set_header 지시어를 사용하여 프록시된 서버로 전달되는 헤더 필드를 변경하거나 제거할 수 있습니다. 이 지시어는 location, server, http 블록 등에서 지정할 수 있습니다.  위 예제에서 [[HTTP#Host|Host]] 필드는 $proxy_host변수로 설정되었다. <syntaxhighlight lang="nginx">
location /some/path/ {
proxy_set_header Accept-Encoding "";
</syntaxhighlight>위 예제에서 Accept-Encoding 필드가 프록시된 서버로 전달되는 것을 방지하기 위하여 빈 문자열로 설정했다.
 
[[Nginx Proxy Manager]]를 사용할 수 있다.
=== Security Controls ===
== http core module ==
https://nginx.org/en/docs/http/ngx_http_core_module.html
=== location ===
==== $scheme ====
request scheme, “http” or “https”
 
==== $host ====
클라이언트 요청 헤더의 Host 필드의 값
== Nginx Http Proxy module ==
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_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]] 메서드에 대한 응답을 추가할 수 있다.
== 보안설정 ==
편집
2,431