Apacheのように: .htaccess

することができませんYou shouldn’t. If you need .htaccess, you’re probably doing it wrong.

なぜ?

いい質問です。まず第一に、.htaccessが動作するには、Apacheは.htaccessファイルをチェックするためにリクエストされたパス内の全てのディレクトリを調べる必要があり、存在するとApacheはそれらの全てを読み込みパースします。これが全てのリクエストに対して起こります。ファイルを変更した瞬間にそれが効果を持つことを思い出してください。これはApacheがそれを毎回読んでいるからです。

Numbers

http://example.com/site/files/images/layout/header.png

エイリアスが散らかっていなくてファイルシステムがパスのように見えるとします。これはそのあたりによくあるほとんどのサイトをカバーします。/ ディレクトリがあり、site/, files/, images/ および layout/ があります。結局.htaccessファイルを持つかもしれない合計5つのディレクトリがあります。/, files/ および images/ に .htaccessを追加したとします。3つの .htaccess ファイルです。これはとてもよくあることです。

Now the numbers, that’s 6 file system stats and 4 file system reads. リクエストされたファイルの1つを含みます。これが各読み込みごとに発生します。We’ll ignore parsing time because both NGINX and Apache need to do this and we’ll consider the difference in time for this negligible.

Requests / Hour NGINX FS Stats NGINX FS Reads Apache FS Stats Apache FS Reads コメント
1 1 1 6 4 Single Request [Pretty much no load]
10 10 10 60 40 Ten Requests [Pretty much no load]
3,600 3,600 3,600 21,600 14,400 1 req/sec [Very low load]
144,000 144,000 144,000 864,000 576,000 40 req/sec [Moderate traffic - nothing very large]
324,000 324,000 324,000 1,944,00 1,296,000 90 req/sec [Higher traffic site - not massive]
576,000 576,000 576,000 3,456,000 2,304,000 160 req/sec [Pretty high traffic - still not massive though]

More Numbers

The default for Apache is to use AllowOverride All. Drupal webサイトでこれを見てみましょう。One image for the theme. If you’re website DocRoot is at /var/www/drupal6/ then we just added more file system stats. これはリクエストごとに3つのstatsを追加します。これが信じられないことに一般的なApache/Drupalセットアップです。It’s the end result of countless guides out there.

/var/www/drupal6/sites/example.com/themes/yourtheme/images/layout/header.png

自身のものを作成しなくてもこのパスの中に2つの.htaccessファイルがあるでしょう。これが一般的なため、/var/www/ の中に1つを追加するとします。

Requests / Hour NGINX FS Stats NGINX FS Reads Apache FD Stats Apache FS Reads コメント
144,000 144,000 144,000 1,296,000 576,000 40 req/sec
324,000 324,000 324,000 2,916,000 1,296,000 90 req/sec
576,000 576,000 576,000 51,840,000 2,304,000 160 req/sec

結論

.htaccessを使うのを止めてください。パフォーマンスが恐ろしいことになります。NGINX は効率的iなように設計されています。このようなものを追加することはそれを破壊します。

TOP
inserted by FC2 system