最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

reactjs - How to clear client browser cache and reflect new changes every time client open website with NGINX? - Stack Overflow

programmeradmin0浏览0评论

I am running Direct react build on NGINX server on GCP VM. The issue I am facing again and again is, Earlier i was opening website as example when I added permanent redirection with NGINX config files to www.example it is getting treated as new website to browser where earlier example was opened. In private tab website is getting redirected to www.example. And in some browsers normal tab with www.example is making cache and new changes are not getting reflected.

Here is my configuration file:

server {
    listen 80;
    server_name example www.example;

    # Redirect HTTP to HTTPS
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl;
    server_name example;

    ssl_certificate /etc/letsencrypt/live/www.example/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/www.example/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

    return 301 $request_uri;
}

server {
    listen 443 ssl;
    server_name www.example;

    ssl_certificate /etc/letsencrypt/live/www.example/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/www.example/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

    root /var/www/html;  # Path to your React build folder
    index index.html;

    location / {
        try_files $uri /index.html;  # Redirect all non-matching routes to index.html
    }

    # Serve static files normally
    location ~* \.(?:ico|css|js|gif|jpe?g|png|woff2?|eot|ttf|otf|svg)$ {
        expires 6M;
        access_log off;
        add_header Cache-Control "public";
    }

    # Deny access to hidden files
    location ~ /\. {
        deny all;
    }
}

I just want where website is working as example there it should redirected to www.example and every time client visits to website it should show latest changes.

Please help.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论