I have a springboot application that serves a page of images. These images live in a directory outside of the application in order to give certain people access to add more photos over a network share. /home/user1/share/static-images. Running this locally I am able to get things to work. But when putting this application behind nginx, I’ve setup the proxy_pass like this:
server {
listen 80;
listen [::]:80;
server_name www.domain.com;
location / {
proxy_pass http://localhost:8080/;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Port $server_port;
}
}
This seems to work as far as it is displaying the page and any local images inside the springboot app. But none of the images from the static path are showing up. I’ve tried adding a path like this:
location /static-images {
root /home/user1/share/static-images;
}
But this throws a 403 forbidden message. I’ve new to nginx, so I’m assuming this is just an nginx configuration problem. Any clues?
3
Answers
Sorry @slauth I am unable to verify if that works. I ended up switching to Apache and this configuration worked.
The requested URL path is appended to the configured
root
. So if someone requestshttp://www.example.com/static-images/img.png
, the URL path is/static-images/img.png
and nginx translates this to/home/user1/share/static-images/static-images/img.png
in your current configuration.Changing the root to
/home/user1/share;
here is probably what you want.please try this
and reload the nginx