問題タブ [static-files]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票する
2 に答える
281 参照

python - Django: 非常に小規模な Web サイトの静的コンテンツ

私は学校の非常に小規模な Web サイト (1 日に 100 人未満のユーザー) に取り組んでおり、静的ファイルを管理するために 2 つ目のサーバーをデプロイする代わりに、django サーバーに静的ファイルを保存する方法があるかどうか疑問に思っていました。Google 検索では次のようなものが見つかります: https://docs.djangoproject.com/en/dev/howto/static-files/ですが、これを行うためのより簡単な方法があったとしても、 Django サーバーではあまり効率的ではありません。

0 投票する
1 に答える
65 参照

python - Django:相互に参照する静的ファイル。

静的ファイルを含むディレクトリがあり、myapp/static/その中に、、、があります。これらのファイルはどのように相互に参照できますか?インスタントの場合、cssは特定のページの背景に画像ファイルを使用する必要があります。URLをハードコーディングする必要がありますか?比較的できますか?static/cssstatic/javascriptstatic/images

0 投票する
2 に答える
3884 参照

rest - レストフル URL の Nginx URL 書き換え

動的な安らかな URL の下に静的ファイルを持つ Rails Web アプリがあります。例えば:

サーバー上の静的ファイルにリダイレクトするようにNginxをセットアップしたい:

1 は動的プロジェクト ID です。

ロケーションブロックと書き換えステートメントは、Nginx 構成ファイルをどのように探しますか?


アップデート

元の質問への回答として、以下の回答にマークを付けました。私の場合、プロジェクトの添付ファイルの URL を書き換える必要はありませんでしたが。Rails ビュー erb で既に URL を再マッピングしていたことを忘れていました。

私の本当の目標は、Thin がキャッシュ応答ヘッダーを添付ファイルに追加するのを阻止することでした。最終的に、次のような添付ファイルの場所を追加するだけで、Nginx でこれを防ぐことができました。

0 投票する
2 に答える
309 参照

node.js - node.js を使用してファイル システムからファイルを提供すると、応答本文が空として返されます

そのため、ファイルがサーバーにアップロードされた後、ファイルをユーザーに提供しようとしています。アップロードされたファイルは、アプリケーション ディレクトリ内の uploads というディレクトリに保存しています。ファイルを提供するために使用しているコードは次のとおりです。

virtualToPhysical は、ファイル システム内のディレクトリへのパスをリクエスト URL に追加するだけです。req.url が「/uploads/image1.jpg」の場合、virtualToPhysical は「/path/to/application/uploads/image1.jpg」を吐き出します。mime.lookup() 呼び出しは、ファイルの正しい MIME タイプを推測する組み込みライブラリからのものです。

このコードはエラーなしで実行されます。応答ヘッダーは問題ないように見えますが、ファイルの種類やサイズに関係なく、本文は毎回空になります。util.pump() を使用して別の方法を試しましたが、同じ結果が得られます。

*編集: * 私はあちこち探し回っていますが、これは文字通り、ノード経由でファイルを提供するために人々が使用すると言う唯一の方法です。私の問題が何であるかについて途方に暮れています。res.end() を呼び出すときに「バイナリ」フラグを使用しないことを誰かが提案しましたが、何があっても同じ効果が発生します。

0 投票する
1 に答える
5292 参照

web-config - 認証による aspnet 静的ファイル アクセス

私のアプリケーション フォルダには、仮想アプリケーション QA があります。html やその他の静的ファイルを含む "help" フォルダーがあります。QA はフォーム認証を使用しています。

ヘルプ フォルダー内のすべてのファイルは、認証なしでアクセスできます (たとえば、www.mypage.com/QA/help/test.html)。ユーザーがヘルプ フォルダー内のファイル (html ファイルまたはその他の静的ファイル) にアクセスすると、ユーザーがログイン ページにリダイレクトされるように、これを変更する必要があります。私が見つけた唯一のことは、これが静的ファイル処理とaspへのマッピングを伴うものであることです。IIS6を使用しています。

このような行を追加しようとしました

私のweb.config(QAフォルダーにあります)に追加しますが、役に立ちません。実際、私はこの行を理解していません。また、web.config ファイルの管理も初めてです。また、ヘルプ フォルダからすべての静的ファイルを QA に入れようとしましたが、これも役に立ちません。

0 投票する
5 に答える
5789 参照

django - Heroku上のgunicornサーバーを使用したDjangoプロジェクトは静的ファイルを提供しません

私のDjango1.3プロジェクトは、開発サーバーで静的ファイルを提供しますが、gunicornサーバーでは静的ファイルは提供されません。このHerokuガイドの手順に従いました。

ガイド()のようにprocfileの内容を使用すると web: gunicorn myproject_django.wsgi -b 0.0.0.0:$PORT、プロジェクトがHerokuに認識されませんでした。

次に、そのProcfileを次のように変更しました。

これで、静的ファイル(cssがアクティブでも画像でもない)を除いてアプリが実行されます。

私のプロジェクトツリー:

settings.pyの潜在的に関連する部分

編集

Francis Yaconielloのエントリー後、次のことを調整しました。

settings.pyで

gitignoreの場合:

その後、コミットしました。そして最後に走っheroku run python myproject_django/manage.py collectstaticた。

しかし、Webページを確認しても、静的ファイルはまだ提供されていません。私のディレクトリツリーを考えると、なぜこれらの変更が機能しなかったのですか?

Edit2

静的ファイルがまだ表示されません。DEBUG=Trueこれを取得しているときに画像をクリックすると、次のようになります。

ツリーstaticfiles(ディレクトリが空であることに注意してください)

settings.pyで

0 投票する
1 に答える
1865 参照

python - `gunicorn_django`を実行すると、静的ファイルのデフォルトの動作が提供されませんか?

myproject_django$ gunicorn_django静的ファイルを除いて私のサイトにサービスを提供します。なぜアイデアはありますか?django1.3を使用して仮想環境からこれを実行しています。

プロジェクトツリー

settings.pyの関連する可能性のある部分

0 投票する
3 に答える
715 参照

python - An "image-serving web framework" in Python?

I'm planning an iOS app that requires a server backend capable of efficiently serving image files and performing some dynamic operations based on the requests it gets (like reading and writing into a data store, such as Redis). I'm most comfortable with, and would thus prefer to write the backend in Python.

I've looked at a lot of Python web framework/server options, Flask, Bottle, static and Tornado among them. The common thread seems to be that either they support serving static files as a development-time convenience only, discouraging it in production, or are efficient static file servers but not really geared towards the dynamic framework-like side of things. This is not to say they couldn't function as the backend, but at a quick glance they all seem a bit awkward at it.

In short, I need a web framework that specializes in serving JPEGs instead of generating HTML. I'm pretty certain no such thing exists, but right now I'm hoping that someone could suggest a solution that works without bending the used Python applications in ways they are not meant for.

Specifications and practical requirements

The images I'd be serving to the clients live in the file system in a shallow directory hierarchy. The actual file names would be invisible to the clients. The server would essentially read the directory hierarchy at startup, assigning a numeric ID for each file, and would route the requests to controller methods that then actually serve the image files. Here are a few examples of ways the client would want to access the images in different circumstances:

  1. Randomly (example URL path: /image/random)
  2. Randomly, each file only once (/image/random_unique), produces some suitable non-200 HTTP status code when the files are exhausted
  3. Sequentially in either direction (/image/0, /image/1, /image/2 etc.)

and so on. In addition, there would be URL endpoints for things like ratings, image info and other metadata, some client-specific information as well (the client would "register" with the server, so that needs some logic, too). This data would live in a Redis datastore, most likely.

All in all, the backend needs to be good at serving image/jpeg and application/json (which it would also generate). The scalability and concurrency requirements are modest, at least to start with (this is not an App Store app, going for ad-hoc or enterprise distribution).

I don't want the app to rely on redirects. That is, I don't want a model where a request to a URL would return a redirect to another URL that is backed by, say, nginx as a separate static file server, leaving only the image selection logic for the Python backend. Instead, a request to a URL from the client should always return image/jpeg, with metadata in custom HTTP headers where necessary. I specify this because it is a way of avoiding serving static files from Python that I thought of, and someone else might think of too ;-)

Given this information, what sort of solution would you consider a good choice, and why? Or is this something for which I need to code non-trivial extensions to existing projects?


EDIT: I've been thinking about this a bit more. I don't want redirects due to the delay inherent in the multiple requests they entail, plus I'd like to abstract out the file names from the client, but I was wondering if something like this would be possible:

A graph of the proposed request flow

It's pretty self-explanatory, but the idea is that the Python program is given the request info by nginx (or whatever serves the role), mulls it over and then tells nginx to respond to the client's request with a specific file from the file system. It does so. The client is none the wiser about how the request was fulfilled, it just receives a response with the correct content type.

This would be pretty optimal in my view, but is it possible? If not with nginx, perhaps something else?

0 投票する
2 に答える
9950 参照

python - Tornado で静的ファイル キャッシュを無効にする

デフォルトでは、Tornado はCache-Control: publicStaticFileHandler. これをどのように変更できCache-Control: no-cacheますか?

0 投票する
1 に答える
4877 参照

django - 収集された静的ファイルを提供するためにnginxを取得できません

nginx を gunicorn と一緒に動作させようとしています。/project/static/静的ファイルがあるディレクトリがあります。これらのファイルは、次の構成/project/livestatic/を使用してディレクトリに収集されます。settings.py

次のnginx構成を使用しています:

開発サーバー (nginx を無視) の下では、この構成は正常に機能し、形式でリンクすることで静的ファイルを提供できます/static/file.extension。ただし、nginx/gunicorn が登場した瞬間、これは機能せず、アクセスしようとするとdomain.org/static/django 404 ページが表示され、nginx がファイルをまったく提供していないことが示されます。どうやって間違ったの?