Ticket #746: nginx.patch

File nginx.patch, 6.2 KB (added by Justin Ellison, 11 years ago)

nginx-config.patch

  • conf.d/default.conf

    From f7c4e5a1fca1ca5c158dc393a44d753b0dccc8a8 Mon Sep 17 00:00:00 2001
    From: root <root@base.vagrant.foo.com>
    Date: Mon, 6 Apr 2015 14:00:48 -0500
    Subject: [PATCH 1/2] working
    
    ---
     conf.d/default.conf |   59 +++++++++++++++++++++++++++++++++++++++++++++-----
     nginx.conf          |   13 ++++++++++-
     2 files changed, 65 insertions(+), 7 deletions(-)
    
    diff --git a/conf.d/default.conf b/conf.d/default.conf
    index 34aeb9a..8de7683 100644
    a b  
     1#
     2# The default server
     3#
    14server {
    2     listen       80;
    3     server_name  localhost;
     5    listen       80 default_server;
     6    server_name  _;
    47
    58    #charset koi8-r;
    6     #access_log  /var/log/nginx/log/host.access.log  main;
     9
     10    #access_log  logs/host.access.log  main;
     11
     12    # Load configuration files for the default server block.
     13    include /etc/nginx/default.d/*.conf;
     14
     15    proxy_cache ae_images;
    716
    817    location / {
    9         root   /usr/share/nginx/html;
    10         index  index.html index.htm;
     18        # Won't need this with our own app
     19        proxy_set_header Host pics.foo.com;
     20        proxy_pass http://image_servers;
     21        #proxy_pass http://pics.foo.com;
     22        # These only take effect if there's no expires/cache-control from the backend
     23        proxy_cache_valid 200 302 10m;
     24        proxy_cache_valid 404      1m;
     25        # Add or append x-forwarded-for
     26        proxy_set_header X-Forwarded-Proto $scheme;
     27        proxy_set_header X-Real-IP $remote_addr;
     28        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
     29        # For keepalive connections, turn this on if version >= 1.1.4
     30        proxy_http_version 1.1;
     31
     32        # Only allow one request for each URI to the backend at a time, e.g.
     33        # 200 clients ask for favico.ico at the same time, only one request hits the
     34        # backend.
     35        # Turn this on if version >= 1.1.12
     36        proxy_cache_lock on;
     37        # The amount of time the lock is placed in the above scenario.
     38        #proxy_cache_lock_age 2s;
     39
     40        # Enable nginx to use if-modified-since and if-none-match to backend
     41        # Turn this on if version >= 1.5.7
     42        proxy_cache_revalidate on;
     43
     44        # Allow nginx to send potentially stale content when:
     45        proxy_cache_use_stale error timeout invalid_header updating
     46                                http_500 http_502 http_503 http_504;
     47        proxy_connect_timeout 5s;
     48        # Replace backend error with our own:
     49        proxy_intercept_errors on;
     50        # TODO should we include 500's here?
     51        proxy_next_upstream error timeout;
     52#TODO do we need to rewrite redirects with proxy_redirect?
     53
    1154    }
    1255
    13     #error_page  404              /404.html;
     56    error_page  404              /404.html;
     57    location = /404.html {
     58        root   /usr/share/nginx/html;
     59    }
    1460
    1561    # redirect server error pages to the static page /50x.html
    1662    #
    server {  
    4389    #}
    4490}
    4591
     92
  • nginx.conf

    diff --git a/nginx.conf b/nginx.conf
    index e4bad8d..0600cc0 100644
    a b http {  
    1515    include       /etc/nginx/mime.types;
    1616    default_type  application/octet-stream;
    1717
     18    upstream image_servers {
     19        server pics.foo.com weight=5;
     20        server mbp.foo.com down;
     21    }
     22    # "One megabyte zone can store about 8 thousand keys."
     23    proxy_cache_path  /usr/share/nginx/data/cache levels=1:2 keys_zone=ae_images:100m max_size=2G inactive=24h;
     24
     25    log_format proxylog  '$remote_addr - $remote_user [$time_local] "$request" '
     26                         '$status $body_bytes_sent "$http_referer" '
     27                         '"$http_user_agent" "$http_x_forwarded_for" $upstream_addr $upstream_response_time';
     28
    1829    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    1930                      '$status $body_bytes_sent "$http_referer" '
    2031                      '"$http_user_agent" "$http_x_forwarded_for"';
    2132
    22     access_log  /var/log/nginx/access.log  main;
     33    access_log  /var/log/nginx/access.log  proxylog;
    2334
    2435    sendfile        on;
    2536    #tcp_nopush     on;
  • conf.d/default.conf

    -- 
    1.7.1
    
    
    From ac2de3f7ee9c1868e8695102300ead1858b01e25 Mon Sep 17 00:00:00 2001
    From: root <root@base.vagrant.foo.com>
    Date: Thu, 9 Apr 2015 10:06:09 -0500
    Subject: [PATCH 2/2] remove revalidation to test
    
    ---
     conf.d/default.conf |    9 ++++++++-
     nginx.conf          |    4 +++-
     2 files changed, 11 insertions(+), 2 deletions(-)
    
    diff --git a/conf.d/default.conf b/conf.d/default.conf
    index 8de7683..82a084b 100644
    a b server {  
    2626        proxy_set_header X-Forwarded-Proto $scheme;
    2727        proxy_set_header X-Real-IP $remote_addr;
    2828        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
     29        # Add diagnostic header
     30        add_header X-Cache-Status $upstream_cache_status;
    2931        # For keepalive connections, turn this on if version >= 1.1.4
    3032        proxy_http_version 1.1;
    3133
    server {  
    3941
    4042        # Enable nginx to use if-modified-since and if-none-match to backend
    4143        # Turn this on if version >= 1.5.7
    42         proxy_cache_revalidate on;
     44        #
     45        # Turning this on comes with a warning, the revalidation doesn't update the expires
     46        # headers on the cached item.  Rather, it holds the object as valid until the
     47        # invalid_time on the store expires before it revalidates again.  Turning this on
     48        # coupled with a high inactive time could result in serving up stale data.
     49        # proxy_cache_revalidate on;
    4350
    4451        # Allow nginx to send potentially stale content when:
    4552        proxy_cache_use_stale error timeout invalid_header updating
  • nginx.conf

    diff --git a/nginx.conf b/nginx.conf
    index 0600cc0..cefc626 100644
    a b events {  
    1414http {
    1515    include       /etc/nginx/mime.types;
    1616    default_type  application/octet-stream;
     17    server_tokens off;
     18
    1719
    1820    upstream image_servers {
    1921        server pics.foo.com weight=5;
    http {  
    2426
    2527    log_format proxylog  '$remote_addr - $remote_user [$time_local] "$request" '
    2628                         '$status $body_bytes_sent "$http_referer" '
    27                          '"$http_user_agent" "$http_x_forwarded_for" $upstream_addr $upstream_response_time';
     29                         '"$http_user_agent" "$http_x_forwarded_for" $upstream_addr $upstream_response_time $upstream_cache_status';
    2830
    2931    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    3032                      '$status $body_bytes_sent "$http_referer" '