2

他のすべてのリクエストがリバースプロキシされている間、運が悪い(404を取得する)ために、nginxが特定のサブディレクトリの下のリクエストに対して静的ファイルを提供するようにしようとしています。たとえば、http://example.com/project/static/index.htmlおよびhttp://example.com/project/static/subdir/file2.htmlへのリクエストを /var/www/example にマップする必要がありますそれぞれ .com/htdocs/index.html と /var/www/example.com/htdocs/subdir/file2.html です。

他のすべてのリクエストはリバース プロキシする必要があります。たとえば、http://example.com/project/thisWillBeProxied.htmlおよびhttp://example.com/project/subdir/soWillThis.html

これが私のアクティブなnginxプロファイルです

server {
    listen   8080;
    server_name  example.com;
    access_log  /var/www/example.com/log/nginx.access.log;
    error_log  /var/www/example.com/log/nginx_error.log debug;

    location / {
            proxy_pass         http://reverse-proxy-host/;
    }

    location ^~ /project/static/ {
            alias   /var/www/example.com/htdocs;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
            root   /var/www/nginx-default;
    }
}
4

2 に答える 2

1

エラー ログは、何が起こっているのかを説明するのに役立ちます。

あなたの設定:

location ^~ /project/static/ {
    alias   /var/www/example.com/htdocs;
}

それはあなたが書いたことを正確に行います。/project/static/URI をファイル パスに置き換えます/var/www/example.com/htdocs。したがって、リクエストが次のように見える場合http://example.com/project/static/index.html、nginx は を開こうとします/var/www/example.com/htdocsindex.html/var/www/example.com/htdocsindex.html私はあなたがサービスを提供したくないがサービスを提供したいと思っていると仮定します/var/www/example.com/htdocs/index.html

location ^~ /project/static/ {
    alias   /var/www/example.com/htdocs/;
}

ドキュメンテーション

于 2012-09-15T13:55:33.510 に答える
0

これを使用してみます: http://wiki.nginx.org/HttpCoreModule#error_page

「リダイレクト中に URI を変更する必要がない場合は、エラー ページの処理を名前付きの場所にリダイレクトすることができます」からお読みください。

このように静的ディレクトリを使用する必要はありません。:)

于 2012-12-11T15:50:55.777 に答える