title: Serving Static Content NGINX
body: <p>I'm new to <a href="http://nginx.com/" rel="nofollow noreferrer"><strong>NGINX</strong></a>. I don't know a lot about it yet, but I'm trying to.
  I'm curious what is the best way to serve the static contents from my page using NGINX. The main reason why I want to serve the static contents is that I want put less load on my application servers, and increase the page load speed.</p>
  <hr />
  <h1>I came across</h1>
  <p>a couple good articles that help me put these together this post : <a href="https://serversforhackers.com/nginx-caching/" rel="nofollow noreferrer">here</a>, <a href="http://nginx.com/resources/admin-guide/serving-static-content/" rel="nofollow noreferrer">here</a>, <a href="https://stackoverflow.com/questions/23776660/how-to-make-nginx-serve-static-content-like-js-css-html">here</a>,  and <a href="https://stackoverflow.com/questions/12806893/use-nginx-to-serve-static-files-from-subdirectories-of-a-given-directory">here</a>.</p>
  <p>But everything is still a little clear.</p>
  <hr />
  <h1>Configuration</h1>
  <p>File Path : <code>etc/nginx/default</code></p>
  <pre><code>server {
  
      listen 80 default_server;
      server_name default;
      root /home/forge/site/public;
  
      location / {
          proxy_pass http://43.35.49.160/;
          try_files $uri $uri/ /index.php?$query_string;
      }
  
      # Media: images, icons, video, audio, HTC
      location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
          expires 1M;
          access_log off;
          add_header Cache-Control &quot;public&quot;;
      }
  
      # CSS and Javascript
      location ~* \.(?:css|js)$ {
          expires 1y;
          access_log off;
          add_header Cache-Control &quot;public&quot;;
      }
  }
  </code></pre>
  <hr />
  <h1>Test/Result</h1>
  <p>After saving my file, I run <code>service nginx reload</code>.</p>
  <p>Next, I tried run : <code>curl -X GET -I  http://45.33.69.160/index.php</code></p>
  <p>I got:</p>
  <pre><code>HTTP/1.1 200 OK
  Server: nginx/1.6.3
  Content-Type: text/html; charset=UTF-8
  Transfer-Encoding: chunked
  Connection: keep-alive
  Cache-Control: no-cache
  Date: Fri, 08 May 2015 15:14:55 GMT
  Set-Cookie: XSRF-TOKEN=eyJpdiI6IkhPa2kwK1wvd2kxMFV0TURzYnMwSXFnPT0iLCJ2YWx1ZSI6IkFpSFpvakNjcGp0b0RWcVViYXJcLzRHbmo3XC9qbStYc2VzYVh4ZHVwNW45UGNQMmltZEhvSys1NjhZVzZmckhzOGRBUk5IU1pGK084VDF1ZmhvVkZ4MlE9PSIsIm1hYyI6IjliMzc5NWQ4MWRiMjM1NzUxNjcyNGNmYWUzMGQyMDk3MjlkYTdhYzgxYTI0OGViODhlMTRjZTI4MWE5MDU2MGYifQ%3D%3D; expires=Fri, 08-May-2015 17:14:55 GMT; Max-Age=7200; path=/
  Set-Cookie: laravel_session=eyJpdiI6Iklhb041MkVBak0rVm5JeUZ0VVwvZ3pnPT0iLCJ2YWx1ZSI6IitRUFlzQzNmSm1FZ0NQVVFtaTJ4cG1hODlDa2NjVDgzdXBcLzRcL0ZSM1ZPOTRvRGo5QjQ1REluTUM3Vjd3cFptV3dWdHJweTY3QW5QR2lwTkZMUlNqbnc9PSIsIm1hYyI6IjIxOTZkYzM5ODE0N2E4YmQzODMxZGYzMDY3NjI4ODM1YWQxNGMxNDRlZDZmMGE1M2IwZWY2OTU4ZmVjOTIyMjkifQ%3D%3D; expires=Fri, 08-May-2015 17:14:55 GMT; Max-Age=7200; path=/; httponly
  </code></pre>
  <p>Then, I tried run <code>curl -X GET -I  http://45.33.69.160/css/custom.css</code></p>
  <p>I got :</p>
  <pre><code>HTTP/1.1 200 OK
  Server: nginx/1.6.3
  Date: Fri, 08 May 2015 15:16:03 GMT
  Content-Type: text/css
  Content-Length: 2890
  Last-Modified: Thu, 07 May 2015 03:02:38 GMT
  Connection: keep-alive
  ETag: &quot;554ad5ce-b4a&quot;
  Accept-Ranges: bytes
  </code></pre>
  <p>Why do I see <code> Cache-Control: no-cache</code> and I just set up the cache ?</p>
  <p>Everything is just unclear to me right now.</p>
  <hr />
  <h1>Questions</h1>
  <p>Can someone please make it clear on how to :</p>
  <ul>
  <li>configure this properly</li>
  <li>test that configuration if it is work</li>
  <li>see the different between caching and not caching</li>
  <li>benchmark it and print out that report on a page or CLI</li>
  </ul>
  <p>?</p>