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.