Nginx reverse proxy giving cache MISS

nginxPROXY

I have configured nginx reverse proxy for domain.
However, when I test using curl, it is showing cache MISS.

curl -I http://www.mixtapemadness.com
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Cache-Control: max-age=0, no-cache, no-store, must-revalidate
Content-Type: text/html; charset=UTF-8
Date: Wed, 23 Nov 2016 13:58:23 GMT
Expires: Wed, 11 Jan 1984 05:00:00 GMT
Pragma: no-cache
Server: nginx/1.8.1
Set-Cookie: ci_session=2fb702c0f6a7528e1198db89b1df85142ee1bfad; 
expires=Wed, 23-Nov-2016 15:58:21 GMT; Max-Age=7200; path=/; HttpOnly
Vary: Accept-Encoding
X-Proxy-Cache: MISS
Connection: keep-alive

My nginx.conf:

user nginx;
worker_processes 8;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
    worker_connections 1024;
}
http {

log_format rt_cache '$remote_addr - $upstream_cache_status [$time_local]  
                    '"$request" $status $body_bytes_sent '
                    '"$http_referer" "$http_user_agent"';
 access_log  /var/log/nginx/access.log rt_cache;
    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;
    server_names_hash_bucket_size 128;

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

gzip                on;
gzip_min_length     1000;
gzip_buffers        4 8k;
gzip_http_version   1.0;
gzip_disable        "msie6";
gzip_types
    text/plain
    text/css
    text/js
    text/xml
    text/javascript
    application/javascript
    application/x-javascript
    application/json
    application/xml
    application/rss+xml
    image/svg+xml;
gzip_vary           on;
gzip_proxied any;
    proxy_cache_path /var/nginx/cache levels=1:2 keys_zone=my_cache:10m max_size=10g
                 inactive=60m use_temp_path=off;
    proxy_cache_key "$scheme$host$request_uri";
    include /etc/nginx/conf.d/*.conf;
    index   index.html index.htm;
    client_max_body_size 50M;
    server {


    listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  localhost;
        root         /usr/share/nginx/html;
        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;
        location / {

       }

    proxy_cache my_cache;
    add_header X-Proxy-Cache $upstream_cache_status;
    proxy_cache_valid  200 302  60m;
    proxy_cache_valid  404      1m;
 proxy_pass       http://127.0.0.1:8080; 
        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }

My domain.conf is given below.

server {
        listen    80;
        server_name  example.com www.example.com;
        access_log /var/log/nginx/mixtape.access.log;
        error_log  /var/log/httpd/yourdomain.com-error_log crit;

location ~* .(gif|jpg|jpeg|png|ico|wmv|3gp|avi|mpg|mpeg|mp4|flv|mp3|mid|js|css|html|htm|wml)$ 
{
        root /var/www/html;
        expires 30d;
        }

location / {
        client_max_body_size    50m;
        client_body_buffer_size 128k;

        proxy_send_timeout   90;
        proxy_buffer_size    128k;
        proxy_buffers     4 256k;
        proxy_busy_buffers_size 256k;
        proxy_temp_file_write_size 256k;
        proxy_set_header   Host   $host;
        proxy_set_header   X-Real-IP  $remote_addr;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header   X-Forwarded-Proto $scheme;
    proxy_cache            my_cache;
    proxy_cache_valid 200 10m;
    add_header X-Proxy-Cache $upstream_cache_status;
        proxy_read_timeout 90;
    proxy_pass   http://127.0.0.1:8080/;
        }
}

Best Answer

The response has "Pragma: no-cache" in it, and "Expires: Wed, 11 Jan 1984 05:00:00 GMT". The cache will never store it. You should either change the headers being sent by the application or try rewriting headers, which requires Nginx built with headers_more.