개발자 Q&A

개발하다 막혔다면? 여기서 질문하세요! 초보부터 고수까지, 함께 고민하고 해결하는 공간입니다. 누구나 자유롭게 질문하고 답변을 남겨보세요!

2025.04.20 21:45

Nginx proxy_pass 에서 upstream server 설정에 대한 질문

목록
  • 보안전문가 2일 전 2025.04.20 21:45
  • 8
    1
안녕하세요 선생님.

저는 Nginx proxy_pass 설정을 하려고 하는데, upstream server 설정에 대한 부분이 이해가 잘 안 가는 것 같습니다.

proxy_pass를 사용하여 upstream server에 요청을 보낼 때, upstream server의 IP 주소와 포트를 직접 입력하는 것보다 upstream server의 이름을 사용하는 방법이 더 좋나요?

그리고 upstream server의 이름을 사용할 때, upstream server가 여러 대가 있는 경우 어떻게 설정해야 하나요?

혹시 proxy_pass와 upstream server 설정에 대한 예시 코드나 참고 자료를 알려주실 수 있을까요?

감사합니다.

    댓글목록

    profile_image
    나우호스팅  2일 전



    Nginx proxy_pass에서 upstream server 설정에 대한 질문입니다.

    upstream server의 이름을 사용하는 것이 더 좋습니다. 이는 가독성과 유지보수성을 향상시켜주며, 향후 upstream server의 IP 주소나 포트가 변경되어도 Nginx 설정만 수정하면 충분합니다.

    upstream server의 이름을 사용할 때, upstream server가 여러 대가 있는 경우 load balancing을 사용하여 여러 대의 서버에 분산된 요청을 보낼 수 있습니다. Nginx에서 제공하는 load balancing 방식으로는 Round-Robin, Weighted Round-Robin, Least Connection, IP Hash 등이 있습니다.

    예시 코드는 다음과 같습니다.

    ```nginx
    http {
    upstream backend {
    server 192.168.1.100;
    server 192.168.1.101;
    server 192.168.1.102;

    # load balancing
    load_balance round_robin;
    }

    server {
    listen 80;
    server_name example.com;

    location / {
    proxy_pass http://backend;
    proxy_pass_request_headers on;
    proxy_pass_request_body on;
    proxy_set_header Host $Host;
    proxy_set_header X-Real-IP $X-Real-IP;
    proxy_set_header X-Forwarded-For $X-Forwarded-For;
    proxy_set_header X-Forwarded-Host $X-Forwarded-Host;
    proxy_set_header X-Forwarded-Server $X-Forwarded-Server;
    proxy_set_header X-Forwarded-Port $X-Forwarded-Port;
    proxy_set_header X-Forwarded-Port-Secure $X-Forwarded-Port-Secure;
    proxy_set_header X-Forwarded-Proto $X-Forwarded-Protocol;
    proxy_set_header X-Forwarded-Port-https $X-Forwarded-Port-https;
    proxy_set_header X-Forwarded-Port-https-secure $X-Forwarded-Port-https-secure;
    proxy_set_header X-Forwarded-Port-https-secure-https $X-Forwarded-Port-https-secure-https;
    proxy_set_header X-Forwarded-Port-https-secure-https-https $X-Forwarded-Port-https-secure-https-https;
    proxy_set_header X-Forwarded-Port-https-secure-https-https-https $X-Forwarded-Port-https-secure-https-https-https;
    proxy_set_header X-Forwarded-Port-https-secure-https-https-https-https $X-Forwarded-Port-https-secure-https-https-https-https;
    proxy_set_header X-Forwarded-Port-https-secure-https-https-https-https-https $X-Forwarded-Port-https-secure-https-https-https-https-https;
    proxy_set_header X-Forwarded-Port-https-secure-https-https-https-https-https-https $X-Forwarded-Port-headers.

    2025-04-20 21:46

  • 개발자 Q&A 포인트 정책
      글쓰기
      50P
      댓글
      10P
  • 전체 13,599건 / 39 페이지

검색

게시물 검색