From 69499addafd130a833df5831aca0b49f7982e2eb Mon Sep 17 00:00:00 2001 From: Christoph Haas Date: Fri, 24 Jun 2016 16:27:14 +0200 Subject: [PATCH] Working nginx vhost configuration added to docs --- README.rdoc | 126 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 114 insertions(+), 12 deletions(-) diff --git a/README.rdoc b/README.rdoc index 63a0261..47523be 100644 --- a/README.rdoc +++ b/README.rdoc @@ -114,23 +114,125 @@ https://www.phusionpassenger.com/library/walkthroughs/deploy/ruby/ownserver/ngin Example nginx vhost config: +## +# You should look at the following URL's in order to grasp a solid understanding +# of Nginx configuration files in order to fully unleash the power of Nginx. +# http://wiki.nginx.org/Pitfalls +# http://wiki.nginx.org/QuickStart +# http://wiki.nginx.org/Configuration +# +# Generally, you will want to move this file somewhere, and start with a clean +# file but keep this around for reference. Or just disable in sites-enabled. +# +# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples. +## + +#proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=assets:768m use_temp_path=off; + +#add_header X-Cache-Status $upstream_cache_status; +#add_header X-Runtime 42; +more_clear_headers 'X-Runtime'; +more_clear_headers 'X-Powered-By'; +more_clear_headers 'Server'; +server_tokens off; + +#passenger_show_version_in_header off; + +#log_format proxy '[$time_local] Cache: $upstream_cache_status $upstream_addr $upstream_response_time $status $bytes_sent $proxy_add_x_forwarded_for $request_uri "$http_referer" "$http_user_agent"'; +#access_log /var/log/nginx/debshots-access.log proxy; + +# Default server configuration +# +#passenger_log_level 5; + server { - listen 85.25.83.22:80 default_server; + listen 85.25.83.22:80 default_server; + #listen 80 default_server; + #listen [::]:80 default_server; + + # SSL configuration + # + # listen 443 ssl default_server; + # listen [::]:443 ssl default_server; + # + # Self signed certs generated by the ssl-cert package + # Don't use them in a production server! + # + # include snippets/snakeoil.conf; + passenger_enabled on; passenger_ruby /home/debshots/.rbenv/versions/2.3.1/bin/ruby; - root /home/debshots/debshots/public; - server_name _; + #passenger_pass_header X-Accel-Redirect; + + #proxy_cache_methods GET HEAD; + + root /home/debshots/debshots/public; + + # Add index.php to the list if you are using PHP + #index index.html index.htm index.nginx-debian.html; + + server_name _; + #proxy_cache assets; + #add_header X-Cache-Status $upstream_cache_status; + #proxy_ignore_headers Cache-Control; + + #add_header X-Debian rocks; + + location /assets/ { + alias /home/debshots/debshots/public/assets/; + expires 1h; + #include debshots_params; + add_header X-Coffee assets; + add_header Cache-Control public; + } + location /logo/ { + alias /home/debshots/debshots/public/logo/; + expires 1h; + add_header X-Coffee logo; + add_header Cache-Control public; + } + location /screenshots/ { + alias /home/debshots/debshots/public/screenshots/; + expires max; + add_header X-Coffee screenshots; + add_header Cache-Control public; + } + location /images/ { + alias /home/debshots/debshots/public/images/; + expires 1h; + add_header X-Coffee images; + add_header Cache-Control public; + } + + # Send thumbnails using X-Sendfile / X-Accel-Redirect + # The correct thumbnail is computed by the Rails application so it cannot be served directly. + location /thumbnail/ { + expires 1d; + add_header X-Coffee thumbnail; + add_header Cache-Control public; + + passenger_set_header X-Sendfile-Type "X-Accel-Redirect"; + passenger_env_var HTTP_X_ACCEL_MAPPING /home/debshots/debshots/public/=/__send_file_accel/; + passenger_pass_header X-Accel-Redirect; + } + + # Send public assets using X-Sendfile / X-Accel-Redirect (e.g. public/images/dummy/...) + location /public/ { + expires 1h; + add_header X-Coffee public; + add_header Cache-Control public; + + passenger_set_header X-Sendfile-Type "X-Accel-Redirect"; + passenger_env_var HTTP_X_ACCEL_MAPPING /home/debshots/debshots/public/=/__send_file_accel/; + passenger_pass_header X-Accel-Redirect; + } + + location /__send_file_accel/ { + internal; + alias /home/debshots/debshots/public/; + } } -=== Enable nginx caching - -mkdir /var/cache/nginx - -chown www-data.www-data /var/cache/nginx - -nginx config… - -proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=my_cache:10m max_size=10g inactive=60m use_temp_path=off; == Supported URL paths (aka routes)