Last active
April 14, 2016 09:47
Star
You must be signed in to star a gist
Prerender Installation to Debian with Nginx Proxy and Caching
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
# Prerender kurulumu | |
sudo locale-gen UTF-8 | |
sudo apt-get update | |
sudo apt-get install -y curl | |
curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash - | |
sudo apt-get install -y nodejs build-essential libfontconfig nginx-extras | |
sudo npm install -g phantomjs | |
sudo npm install -g prerender | |
sudo npm install -g pm2 | |
echo “export LC_ALL=en_US.UTF-8” >> ~/.bashrc | |
echo “export PRERENDER_NUM_WORKERS=4” >> ~/.bashrc | |
source ~/.bashrc | |
sudo dpkg-reconfigure locales | |
pm2 start prerender | |
# copy nginx configuration | |
sudo cp prerender.conf /etc/nginx/sites-enabled/. | |
sudo /etc/init.d/nginx restart |
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
lua_shared_dict expire_queue 10m; | |
proxy_cache_path /tmp/nginx/ levels=1:2 keys_zone=default:10m; | |
server { | |
listen 80; | |
server_name prerender.mydomain.com; | |
location / { | |
header_filter_by_lua ' | |
if ngx.header["X-Expire-Content"] then | |
ngx.log(ngx.INFO, "Backend sent invalidation header, adding to the queue " .. ngx.header["X-Expire-Content"]) | |
ngx.shared.expire_queue:add(ngx.header["X-Expire-Content"],1) | |
end | |
'; | |
set_by_lua $http_cache_purge ' | |
local expire = ngx.shared.expire_queue:get(ngx.var.uri) | |
if expire then | |
ngx.log(ngx.INFO, "Removing URL from queue and invalidating, " .. ngx.var.uri) | |
ngx.shared.expire_queue:delete(ngx.var.uri) | |
end | |
return expire | |
'; | |
add_header X-Cached $upstream_cache_status; | |
proxy_cache_bypass $http_cache_purge; | |
proxy_cache default; | |
proxy_cache_valid 200 302 72h; | |
proxy_pass http://127.0.0.1:3000; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For client config use https://gist.github.com/thoop/8165802