1 year ago

#44682

test-img

John Doyle

Nginx server cannot cache the contents of a webpage

I am new to nginx and I am trying to cache my website. I have a website A that redirects the user to the website B if there is no cache stored. Ideally, the website A should show the "old" version of the website B because website B gets updated every second (it is a website involving stock price) while website A should cache the data loaded from website B.

However, whenever the website B gets updated, the website A too gets updated instantly and the website A does not show the "old version" of the website B.

Here is my cache.conf.

proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=custom_cache:10m inactive=10m;


upstream origin_server {
        server [website A server]:8000;
}

server {
        listen 80;
        server_name  _;

    location / {
            include proxy_params;
            proxy_pass http://origin_server;

            proxy_cache custom_cache;
            proxy_cache_valid any 10m;
            add_header X-Proxy-Cache $upstream_cache_status;
    }
}

And here is my website A server.

server {
        listen 8000;

        root /var/www/html;


        index index.html index.htm;

        server_name visualization.jaye.world;

        location / {
                return 301 [website B url]$request_uri;
                try_files $uri $uri/ =404;
        }


}

I am completely new to nginx, and this problem has been bugging me for two days. Thank you for your help in advance.

nginx

nginx-config

nginx-cache

0 Answers

Your Answer

Accepted video resources