Score:1

Nginx throwing 404 errors when assets from subfolder of the root are requested

cw flag

My nginx config file looks like:

passenger_enabled on;
passenger_ruby /home/inspection/.rbenv/shims/ruby;
rails_env    production;

root         /home/inspection/app/current/public;

location /build/ {
root /home/inspection/app/current/public;
autoindex off;
}

if (-f $document_root/under_maintenance.html) {
        return 503;
}
error_page 503 @maintenance;
location @maintenance {
        rewrite ^(.*)$ /under_maintenance.html break;
}

# redirect server error pages to the static page /50x.html
error_page   500 502 503 504  /50x.html;
location = /50x.html {
        root   html;
}

But none of the assets inside the build directory are coming and giving 404. for e.g. https://docking-new.dockingpro.com/build/static/js/runtime-main.1f1f19a3.js if you try you see 404 error.

All files that are inside root folder directly are accessible.

What I need to change here?

Score:0
by flag

The error seem to be in location /build/ When you specify a root inside a location block, Nginx concatenates the root path and the requested URI to generate the final path. Lets remove the root directive from the location /build/ block

Here is your updated code:

passenger_enabled on;
passenger_ruby /home/inspection/.rbenv/shims/ruby;
rails_env    production;

root         /home/inspection/app/current/public;

location /build/ {
    autoindex off;
}

if (-f $document_root/under_maintenance.html) {
    return 503;
}
error_page 503 @maintenance;
location @maintenance {
    rewrite ^(.*)$ /under_maintenance.html break;
}

# redirect server error pages to the static page /50x.html
error_page   500 502 503 504  /50x.html;
location = /50x.html {
    root   html;
}

restart sudo systemctl restart nginx and it should work.

Arup Rakshit avatar
cw flag
I just did what you said but same errors. See https://www.dropbox.com/s/6rbl4f35880fd3p/Screenshot%202023-03-30%20at%2011.40.46%20AM.png?dl=0
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.