0

i am new in nginx and i cant access my public files please guide me i am very new on doing this.

this is my code on express js

app.use('/p',auth, express.static('public/uploads'),
serveIndex('public/uploads', {'icons': true}))

and this is the code on nginx

location =/file/{
proxy_pass http://localhost:8081/p/;
}

it does work like this on my page when i go to http://mywebsite.com/file/ but when we click a file here which will show that directory. it will error out or stay white screen

enter image description here

here is the full code of the location 
    #this is the file system
location =/file/{
proxy_pass http://localhost:8081/p/;
}
    #this is the express api
location /v1
{
        rewrite ^/v1/(.*)?$ /$1 break;
        proxy_http_version 1.1;
        proxy_cache_bypass $http_upgrade;

        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://localhost:8081;
}
    #this is the front end
location /
{
                proxy_http_version 1.1;
                proxy_cache_bypass $http_upgrade;

                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection 'upgrade';
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://localhost:5000;
}
Rei Gner
  • 125
  • 11
  • Is there a reason why you want to serve static files through node/express and not through nginx? See https://stackoverflow.com/a/44796116/3761628 for a related question. – eol Jun 08 '21 at 15:44
  • this file folders is protected by express by authentication from the user you see this are private files is there any good way of doing this. this is what i came up with and right now because of the mix up of locations i cant now serve my files correctly – Rei Gner Jun 08 '21 at 16:08

0 Answers0