4

I have a nginx (:80) and an upstream server (:8080) running on my machine.

  • I want to proxy all requests to /assets/(*.?) to upstream's /upstream/$1 location.
  • The upstream server redirects (302) /upstream/file_id to the /real/file/location.ext

Here is my code:

location /assets/ {
    rewrite ^/assets/(.*) /upstream/$1 break;
    proxy_pass http://127.0.0.1:8000;
}

This seems to work, but on the client side I get the redirected location:

http://myserver.com/real/file/location.ext

I kinda want to hide it so that it stays:

http://myserver.com/assets/file_id

The idea behind this is to make the upstream server find the real file's location, but let the nginx serve the file without giving away its real location. Is this even possible?

4

1 に答える 1

-1

最初にproxy_passで8000を使用していますが、ポートが8080であると言及しています.

次に、実際にここで書き換えルールを使用していて、proxy_pass 行に到達しないため、書き換え行を削除するとうまくいくはずです。次のようなものが機能するはずです。

location /assets/ {
    include proxy_params;
    proxy_pass http://127.0.0.1:8080;
}

このアップストリームリダイレクトを nginx によって内部的に処理するのに役立つ proxy_rewrite および proxy_redirect コマンドもあります。

それが役立つことを願っています!

于 2013-09-10T11:25:52.790 に答える