Skip to content

Instantly share code, notes, and snippets.

@theozaurus
Created November 26, 2010 17:17
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save theozaurus/716974 to your computer and use it in GitHub Desktop.
Save theozaurus/716974 to your computer and use it in GitHub Desktop.
foobar.conf
# Enable upload_progress module for easy cross browser progress bar support
# using only javascript client side
upload_progress foobar_uploads 1m;
server {
# We only need one server block to deal with HTTP and HTTPS
# avoids duplication
listen 80;
listen 443 default ssl;
server_name foobar.com;
# Sort out redirects
## If it has come from localhost - dont mess, handy for services running locally
if ($host = localhost ) { break; }
## If another domain name has resolved to this server (e.g. www.foobar.com)
## then redirect it permanently to the name we really want
if ($host != $server_name) { rewrite ^ $scheme://$server_name$request_uri permanent; }
# Rails isn't interested by default in any other type of request
# so deal with them here
if ($request_method !~ ^(GET|HEAD|PUT|POST|DELETE|OPTIONS)$ ){
return 405;
}
# We follow a convention of each site having it's own user account
# with a Capistrano esque layout
root /home/foobar/foobar/current/public;
# PCI Compliant settings
ssl_protocols SSLv3 TLSv1;
ssl_ciphers ALL:!aNULL:!ADH:!eNULL:!LOW:!MEDIUM:!EXP:RC4+RSA:+HIGH;
ssl_prefer_server_ciphers on;
# Do not forget to include all certificates for chain in this file
ssl_certificate /etc/nginx/certificates/foobar.com.crt;
ssl_certificate_key /etc/nginx/certificates/foobar.com.key;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 5m;
# Your favorite error pages
error_page 404 /404.html;
error_page 422 /422.html;
error_page 500 /500.html;
# Simple way to serve static content and maintenance page if maintenance page present
try_files $uri /maintenance.html @passenger;
# We are not interested in uploads that are larger than 10MB
client_max_body_size 10m;
# Reached if no maintenance page or static content can fulfill request
location @passenger {
passenger_enabled on;
passenger_min_instances 2;
rack_env production;
# Make sure that Rails knows whether the connection was encrypted or not
passenger_set_cgi_param HTTP_X_FORWARDED_PROTO $scheme;
# Enable tracking of POST requests
track_uploads foobar_uploads 30s;
}
# Enable monitoring of POST requests reported in JSON
location /progress {
upload_progress_json_output;
report_uploads foobar_uploads;
}
access_log /var/log/nginx/foobar.access.log;
}
# Starts passenger after nginx is rebooted
# Rather than on first request
passenger_pre_start http://foobar.com/;
@mikhailov
Copy link

what do you think about --with-http_gzip_static_module and gzip_static on; directive?
http://wiki.nginx.org/HttpGzipStaticModule

@theozaurus
Copy link
Author

Those are enabled in the http section of nginx.conf in a similar way to yours.

http {
  include       /etc/nginx/mime.types;
  default_type  application/octet-stream;

  access_log    /var/log/nginx/access.log;

  sendfile on;
  tcp_nopush on;
  tcp_nodelay on;

  keepalive_timeout  65;

  gzip  on;
  gzip_http_version 1.1;
  gzip_comp_level 2;
  gzip_proxied any;
  gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript;
  gzip_vary on;

  server_names_hash_bucket_size 64;

  include /etc/nginx/conf.d/*.conf;
  include /etc/nginx/sites-enabled/*;
}

The compile options I use are:

# /opt/nginx-0.8.53/sbin/nginx -V
nginx version: nginx/0.8.53
built by gcc 4.2.4 (Ubuntu 4.2.4-1ubuntu4)
TLS SNI support disabled
configure arguments: --prefix=/opt/nginx-0.8.53 --with-http_ssl_module --add-module=/opt/ruby-enterprise/lib/ruby/gems/1.8/gems/passenger-3.0.0/ext/nginx --prefix=/opt/nginx-0.8.53 --conf-path=/etc/nginx/nginx.conf --with-http_ssl_module --with-http_gzip_static_module --add-module=/usr/local/src/nginx_upload_progress-v0.8.2

We should probably add in the msie6 options that you use, as it seems that is to get around a cache bug?! I'm interested in how you picked buffer and min_length values as well. We've not started to play with that at all.

@theozaurus
Copy link
Author

Seem's we're totally missing out the gzip_static goodness. That looks great.

@mikhailov
Copy link

I have updated config file with gzip_static and nginx installation tips.
you can take a look https://gist.github.com/711913

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment