J
J
jeruthadam2019-08-07 16:54:01
Nginx
jeruthadam, 2019-08-07 16:54:01

Why doesn't proxying static files work?

There is a config that simply gives the contents of the directory

server {
    listen 80;

    server_name media.static;
    root /home/myname/stuff;

    location / {
      autoindex on;      
    }
}

Files are available from the browser, everything is ok. The folder structure is like this
/home/myname/stuff/название_домена/static/robots.txt

Now I'm trying to use these files in another config, but it doesn't work
upstream public-api {
  server public.api;
}

upstream media-static {
  server media.static;
}

server {
  listen 80 default_server;
  listen [::]:80 default_server;

  location / {
    proxy_pass http://front/;
  }

  location /robots.txt {
    proxy_pass http://media-static/$host/static;
  }
}

Why doesn't it work and how can I get the file through a proxy?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2019-08-07
@jeruthadam

location /robots.txt {
    proxy_pass http://media-static/$host/static;
  }

Add $uri Or explicitly specify /robots.txt
proxy_pass http://media-static/$host/static/robots.txt;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question