skip to Main Content

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


  1. Chosen as BEST ANSWER

    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>
    

  2. 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.

    Login or Signup to reply.
  3. please try this

    location /static-images/ {
       alias /home/user1/share/static-images/;
       }
    

    and reload the nginx

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search