Created
June 17, 2013 07:58
-
-
Save feiz/5795317 to your computer and use it in GitHub Desktop.
try_filesとinternal path(@xxx)を使って静的ファイルをややこしくserveするnginx.confのjinja2 template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server { | |
# UAからOSを検出 | |
set $osversion ""; | |
if ($http_user_agent ~ "AppleWebKit/(\d{3})"){ | |
set $osversion ".AppleWebKit.$1"; | |
} | |
# manifestファイルはOS個別のものがあればそちらを出す | |
# なければ/static/manifest/にあるデフォルトを使う | |
location ~* /static/manifest.*/(.*\.manifest)$ { | |
default_type text/cache-manifest; | |
set $name $1; | |
{% if override %}# overrideオンの時はrepo/_override/staticにあるものを先に探し、そこに無ければrepo/staticを探す。 | |
root /var/www/repo/_override; | |
try_files /static/manifest$osversion/$name $uri @manifest; | |
} | |
location @manifest { | |
{% endif %} | |
root /var/www/repo; | |
try_files /static/manifest$osversion/$name $uri =404; | |
} | |
location /static/ { | |
types { | |
application/x-javascript js minified; | |
} | |
# 非デバッグ環境では全てのjsを同一ディレクトリにある{ファイル名}.minifiedに置き換える | |
{% if not js_debug %}rewrite (.*.js$) $1.minified;{% endif %} | |
{% if override %}# manifestと同様のコンテンツ上書き | |
root /var/www/repo/_override; | |
try_files $uri @static; | |
} | |
location @static { | |
{% endif %} | |
root /var/www/repo; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
やりたいこと自体はかなり綺麗に実現できたが、メンテナビリティがクソすぎて死にたい。