92

シンアプリ サーバーを使用しようとしていたところ、1 つの問題がありました。

アプリケーションを使用して、 nginxが要求を Thin (または Unicorn) にプロキシproxy_pass http://my_app_upstream;すると、 nginx によって送信された変更された URL が受信されます ( http://my_app_upstream)。

私が望むのは、アプリが大きく依存しているため、元の URL とクライアントからの元の要求を変更せずに渡すことです。

nginx のドキュメントには次のように書かれています。

未処理の形式で URI を送信する必要がある場合は、URI 部分なしでディレクティブ proxy_pass を使用する必要があります。

しかし、関連するサンプルが実際に URI を使用しているため、それを正確に構成する方法がわかりません。

location  /some/path/ {
  proxy_pass   http://127.0.0.1;
}

クライアントからの元のリクエスト URLを保持する方法を教えてください。

4

8 に答える 8

154

proxy_set_headerディレクティブが役立つと思います:

location / {
    proxy_pass http://my_app_upstream;
    proxy_set_header Host $host;
    # ...
}
于 2011-04-29T16:25:44.763 に答える
11

私の場合、proxy_set_header Host $host ミスポートだけです。解決方法:



    location / {
     proxy_pass http://BACKENDIP/;
     include /etc/nginx/proxy.conf;
    }

そしてproxy.confで



    proxy_redirect off;
    proxy_set_header Host $host:$server_port;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

于 2013-06-12T19:37:49.820 に答える
3

absoluteURIリクエストとHostヘッダーのを切り刻むことなく完全に転送するには:

server {
    listen 35005;

    location / {
        rewrite            ^(.*)$   "://$http_host$uri$is_args$args";
        rewrite            ^(.*)$   "http$uri$is_args$args" break;
        proxy_set_header   Host     $host;

        proxy_pass         https://deploy.org.local:35005;
    }
}

ここにあります: https://opensysnotes.wordpress.com/2016/11/17/nginx-proxy_pass-with-absolute-url/

于 2017-07-13T07:58:42.387 に答える
-1

私の認証サーバーの場合...これは機能します。私は自分の人間味のある可読性のために /auth のオプションを用意したいと思っています... または、マシンからマシンへのポート/アップストリームで構成しています。

.

confの最初に

####################################################
upstream auth {
    server 127.0.0.1:9011 weight=1 fail_timeout=300s;
    keepalive 16;
  }

私の443サーバーブロックの内部

          if (-d $request_filename) {
          rewrite [^/]$ $scheme://$http_host$uri/ permanent;
      }

  location /auth {
          proxy_pass http://$http_host:9011;
          proxy_set_header Origin           http://$host;
          proxy_set_header Host             $http_host:9011;
          proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
          proxy_set_header Upgrade          $http_upgrade;
          proxy_set_header Connection       $http_connection;
          proxy_http_version 1.1;
      }

confの一番下に

#####################################################################
#                                                                   #
#     Proxies for all the Other servers on other ports upstream     #
#                                                                   #
#####################################################################


#######################
#        Fusion       #
#######################

server {
    listen 9001 ssl;

#############  Lock it down  ################

# SSL certificate locations
    ssl_certificate /etc/letsencrypt/live/allineed.app/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/allineed.app/privkey.pem;

# Exclusions

    include snippets/exclusions.conf;

# Security

    include snippets/security.conf;
    include snippets/ssl.conf;

# Fastcgi cache rules

    include snippets/fastcgi-cache.conf;
    include snippets/limits.conf;
    include snippets/nginx-cloudflare.conf;

###########  Location upstream ##############

    location  ~ / {
        proxy_pass http://auth;
        proxy_set_header Origin           http://$host;
        proxy_set_header Host             $host:$server_port;
        proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
        proxy_set_header Upgrade          $http_upgrade;
        proxy_set_header Connection       $http_connection;
        proxy_http_version 1.1;
    }
        if (-d $request_filename) {
        rewrite [^/]$ $scheme://$http_host$uri/ permanent;
    }
}
于 2018-11-06T22:33:37.390 に答える