Reputation: 83
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?
Upvotes: 0
Views: 783
Reputation: 341
please try this
location /static-images/ {
alias /home/user1/share/static-images/;
}
and reload the nginx
Upvotes: 1
Reputation: 83
Sorry @slauth I am unable to verify if that works. I ended up switching to Apache and this configuration worked.
<Virtualhost *:80>
ServerName domain.com
ServerAlias www.domain.com
ProxyPreserveHost On
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
</Virtualhost>
Upvotes: 0
Reputation: 3178
The requested URL path is appended to the configured root
. So if someone requests http://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.
Upvotes: 0