주 메뉴 열기

wwiki β

바뀜

Nginx

644 바이트 추가됨, 2023년 11월 4일 (토) 01:01
에러
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