Nginx

caching

Server and Location block Selection

try_files directive

  • try to match the URI with a physical location on disk and provide fallback action
  • Very Good reference about try_files
  • redirect to named location by using error_page
      # Use only codes  greater than 418, do not use common status codes 404, 402, 403, etc
    
      location /js {
        error_page 418 = @backend; return 418;
      }
    
      location /data {
        error_page 418 = @backend; return 418;
      }
    
      location @backend {
        rewrite ^/(.+)$ /backend-url-prefix/$1 break;
    
        proxy_pass   http://127.0.0.1:82;
        proxy_redirect     off;
    
        proxy_set_header   Host             $host;
        proxy_set_header   X-Real-IP        $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;    
      }
    

Logging

error_log directive

  • This is in core module unlike access_log
    • Syntax: error_log file [level];
    • Default: error_log logs/error.log error;
    • Context: main, http, mail, stream, server, location
    • log level: debug, info, notice, warn, error, crit, alert, or emerg.

access_log directive in ngx_http_log_module

  • Syntax: access_log path [format [buffer=size] [gzip[=level]] [flush=time] [if=condition]];
    • access_log off; : disable access_log
  • Default: access_log logs/access.log combined;
  • Context: http, server, location, if in location, limit_except
  • e.g.)
    • access_log /var/log/nginx/blog.test.com-access_log mtest
      • mtest is log_format name like this in http context
        log_format           mtest  '===> $uri | $request_uri | $args';
        

variables $request_uri / $uri / $args

  • e.g.) blog.gatsbylee.com/wp-login.php
    • $uri: /wp-login.php
    • $request_uri: /wp-login.php
    • $args: -
  • e.g.) blog.gatsbylee.com/wp-admin/load-styles.php?c=1&dir=ltr&load%5B%5D=dashicons,buttons,forms,l10n,login&ver=4.6.1
    • $uri: /wp-admin/load-styles.php
    • $request_uri: /wp-admin/load-styles.php?c=1&dir=ltr&load%5B%5D=dashicons,buttons,forms,l10n,login&ver=4.6.1
    • $args: c=1&dir=ltr&load%5B%5D=dashicons,buttons,forms,l10n,login&ver=4.6.1
  • e.g.) blog.gatsbylee.com/wp-content/plugins/login-recaptcha/css/style.css?ver=4.6.1
    • $uri: /wp-content/plugins/login-recaptcha/css/style.css
    • $request_uri: /wp-content/plugins/login-recaptcha/css/style.css?ver=4.6.1
    • $args: ver=4.6.1
Last modified 3 years ago Last modified on 11/27/16 01:36:04