I have 2 npm scripts. One build maintenance folder. Second one deletes maintenance folder and build dist folder. My goal is when maintenance folder exists serve its content and redirects every request to its index.html. These folders structure is ./index.html, ./1.png, ./2.png, ./assets/bundle.js, ./assets/bundle.css, ./assets/3.png, ./assets/font.woff2. My current nginx config:
server {
listen 443 ssl http2;
server_name my-site.com;
ssl_certificate /etc/nginx/ssl/cert.crt;
ssl_certificate_key /etc/nginx/ssl/cert.key;
root /home/user1/site/dist/;
index index.html index.htm index.nginx-debian.html;
error_page 401 /;
# MAINTENANCE MODE
error_page 503 @maintenance;
if (-f /home/user1/site/maintenance/index.html) {
return 503;
}
location @maintenance {
root /home/user1/site/maintenance;
if (!-f $request_filename) {
rewrite ^(.*)$ /index.html break;
}
return 200;
}
# Normal mode
location / {
try_files $uri $uri/ =404;
}
# other backend proxy_pass locations
}
There is a 503 status for every file in Chrome DevTools but html is visible and assets are not. Config above is what i have come to after day of research. I have a feeling i need to fix one or two strings to make it work, but i'm newbie in nginx.