3

I am trying to implement nginx-cache using nginx.conf file. I have referred the code from here

Regards to that, I am using proxy_cache_ upstream.

Below is the error that I am facing if I use proxy_cache_ directive. (I have commented other proxy_cache directive and just use proxy_cache_revalidate so I get below error)

I am running Nginx as a Docker container. (Not sure, if this is the reason why I am encountering these errors)

2018/10/16 04:23:39 [emerg] 1#1: unknown directive "proxy_cache_revalidate on" in /etc/nginx/nginx.conf:127 nginx: [emerg] unknown directive "proxy_cache_revalidate on" in /etc/nginx/nginx.conf:127

Below is my conf file.

thread_pool default threads=32 max_queue=65536;

events { worker_connections 102400; }

http {
    sendfile on;
    sendfile_max_chunk 2048k;
    access_log off; 
    #Implementing NGINX Cache
    proxy_cache_path /usr/nginx-cache levels=1:2 keys_zone=nginx_cache:10m max_size=10g inactive=60m use_temp_path=off;   

    upstream licenseportal {
        server xx.xx.xx.xx:9006;
    }

    upstream publisherportal {
        server xx.xx.xx.xx:9001;
    }

    upstream supportportal {
        server xx.xx.xx.xx:9010;
    }

server {
        listen 8765;

        location /licenseportal/ {
            proxy_pass         http://licenseportal/;
            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;
            proxy_set_header   X-Forwarded-Host $server_name;
            #Implementing NGINX Cache
            proxy_cache nginx_cache; 
            proxy_cache_revalidate on;
            #proxy_cache_min_uses 3;
            #proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
            #proxy_cache_background_update on;
            #proxy_cache_lock on;
            #proxy_cache_methods GET; 
        }


        location /publisherportal/ {
            proxy_pass         http://publisherportal/;
            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;
            proxy_set_header   X-Forwarded-Host $server_name;
            # #timeout setting added
            fastcgi_read_timeout 7200s; 
            send_timeout 7200s;
            proxy_connect_timeout 7200s;
            proxy_send_timeout 7200s;
            proxy_read_timeout 7200s;
            #new property added
            proxy_request_buffering off;
            proxy_buffering off;
            #Implementing NGINX Cache
            proxy_cache nginx_cache; 
            #proxy_cache_revalidate on;
            #proxy_cache_min_uses 3;
            #proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
            #proxy_cache_background_update on;
            #proxy_cache_lock on;
            #proxy_cache_methods GET; 
        }

        location /supportportal/ {
            proxy_pass         http://supportportal/;
            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;
            proxy_set_header   X-Forwarded-Host $server_name;
            #Implementing NGINX Cache
            proxy_cache nginx_cache; 
            #proxy_cache_revalidate on;
            #proxy_cache_min_uses 3;
            #proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
            #proxy_cache_background_update on;
            #proxy_cache_lock on;
            #proxy_cache_methods GET; 
        }
    }
}

Please let me know what changes I need to do in my conf file.

Anand Deshmukh
  • 1,086
  • 2
  • 17
  • 35
  • 1
    Considering that `proxy_cache_revalidate on` appears to contain an embedded space, are you sure its a space character between the directive and the `on`? Try editing the file, deleting the apparent space and inserting a new one. – Richard Smith Oct 16 '18 at 09:41

1 Answers1

0

It sounds like I did some copy and paste work here. It's not uncommon to snag some extra characters that are invisible at the end of line (EOL). So I Tried this:

Run your text through this tool: http://www.textfixer.com/tools/remove-line-breaks.php

then fix any breaks that may have been removed and will be affected by the comments.

This worked for me.

Anand Deshmukh
  • 1,086
  • 2
  • 17
  • 35