Skip to content

Instantly share code, notes, and snippets.

@qfox
Last active August 29, 2015 14:03
Show Gist options
  • Save qfox/961143fb178056eb9188 to your computer and use it in GitHub Desktop.
Save qfox/961143fb178056eb9188 to your computer and use it in GitHub Desktop.
bem nginx conf
if ($postfix) {
set $postfix "-$postfix";
}
if ($pages_path = "") {
set $pages_path "desktop.bundles";
}
set $pages_path "$pages_path$postfix";
# /favicon.ico
rewrite ^/favicon.ico$ /$pages_path/favicon.ico last;
# / => /desktop.bundles-desktop/index
rewrite ^/(\?.*)?$ /$pages_path/index/index.html$1 last;
rewrite ^/_(?:\w+)\.(js|css|\w+\.css)(\?.*)?$ /$pages_path/index/_index.$1$2 last;
# /page => /$pages_path/page/page.html
rewrite ^/(\w+)/(\?.*)?$ /$pages_path/$1/$1.html$2 last;
# css, js
rewrite ^/(\w+)/_(?:\w+)\.(js|css|\w+\.css)(\?.*)?$ /$pages_path/$1/_$1.$2$3 last;
# add final slash to url
rewrite ^/([^?/.]+)(\?.*)?$ /$1/$2 permanent;
rewrite ^/([^?]+/[^?/.]+)(\?.*)?$ /$1/$2 permanent;
upstream bem-server-alex-home {
server localhost:8089;
}
server {
listen 80;
server_name bem.dev.local;
# set $pages_path "pages"; # if need
# set $postfix;
location / {
include /etc/nginx/conf.d/rewrite/bem;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Host $http_host;
proxy_pass http://bem-server-alex-home;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment