{"id":1463,"date":"2014-11-18T09:55:47","date_gmt":"2014-11-18T09:55:47","guid":{"rendered":"http:\/\/41j.com\/blog\/?p=1463"},"modified":"2014-11-18T09:55:47","modified_gmt":"2014-11-18T09:55:47","slug":"nginx-caching-reverse-proxy-configuration","status":"publish","type":"post","link":"https:\/\/41j.com\/blog\/2014\/11\/nginx-caching-reverse-proxy-configuration\/","title":{"rendered":"Nginx caching reverse proxy configuration"},"content":{"rendered":"<p>I was pretty impressed by how easy it was to get Nginx to work as a caching reverse proxy. I run a slightly odd configuration where my host throws out ssh tunnels to an EC2 instance, this then feeds into Cloudflare for CDN.<\/p>\n<p>I decided to put Nginx in the middle. While Cloudflare is good, it doesn&#8217;t really do much by way of aggressive caching and the SSH tunnels were still getting hit pretty hard. In the free Cloudflare plan you don&#8217;t get much control over this anyway. <\/p>\n<p>So I switched up my tunnels and installed Nginx on the EC2 instance. Configured this as a reverse proxy and set reasonably aggressive caching. Config follows:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nuser www-data;\r\nworker_processes 4;\r\npid \/run\/nginx.pid;\r\n\r\nevents {\r\n\tworker_connections 768;\r\n\t# multi_accept on;\r\n}\r\n\r\nhttp {\r\n\r\n\t##\r\n\t# Basic Settings\r\n\t##\r\n\r\n\tsendfile on;\r\n\ttcp_nopush on;\r\n\ttcp_nodelay on;\r\n\tkeepalive_timeout 65;\r\n\ttypes_hash_max_size 2048;\r\n\t# server_tokens off;\r\n\r\n\t# server_names_hash_bucket_size 64;\r\n\t# server_name_in_redirect off;\r\n\r\n\tinclude \/etc\/nginx\/mime.types;\r\n\tdefault_type application\/octet-stream;\r\n\r\n\t##\r\n\t# Logging Settings\r\n\t##\r\n\r\n\taccess_log \/var\/log\/nginx\/access.log;\r\n\terror_log \/var\/log\/nginx\/error.log;\r\n\r\n\t##\r\n\t# Gzip Settings\r\n\t##\r\n\r\n\tgzip on;\r\n\tgzip_disable &quot;msie6&quot;;\r\n\tproxy_cache_path \/data\/nginx\/cache keys_zone=one:10m;\r\n\r\n\tserver {\r\n\t\tlisten 80;\r\n\t\tproxy_cache one;\r\n\t\tproxy_cache_min_uses 100;\r\n\t\tproxy_cache_valid 200 302 30m;\r\n\t\tproxy_cache_valid 404      1m;\r\n\t\t    proxy_set_header Host $host;\r\n\t\tlocation \/ {\r\n            \t\tproxy_pass http:\/\/localhost:8090;\r\n        \t}\r\n    \t}\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I was pretty impressed by how easy it was to get Nginx to work as a caching reverse proxy. I run a slightly odd configuration where my host throws out ssh tunnels to an EC2 instance, this then feeds into Cloudflare for CDN. I decided to put Nginx in the middle. While Cloudflare is good, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1],"tags":[],"class_list":["post-1463","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p1RRoU-nB","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/posts\/1463","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/comments?post=1463"}],"version-history":[{"count":1,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/posts\/1463\/revisions"}],"predecessor-version":[{"id":1464,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/posts\/1463\/revisions\/1464"}],"wp:attachment":[{"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/media?parent=1463"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/categories?post=1463"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/tags?post=1463"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}