B
B
bozuriciyu2019-08-27 00:17:56
Nginx
bozuriciyu, 2019-08-27 00:17:56

How to give the contents of the directory by proxy_pass?

On one server there is a config that just gives static content

server {
    listen 80;

    server_name static.server;
    root /var/www/cms;

    location / {
      autoindex on;
    }
}

Files are publicly available in the browser. In the folder /var/www/cms directories with domain names.
On another server I try to use in proxy_pass but nothing works
upstream static-server {
  server static.server;
}

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

  location /static {
    proxy_pass http://static-server/$host/;
  }
}

How to give the contents of the $host folder by location /static (the host name corresponds to the directory name)?
I made one file to work, but returning the entire contents of the directory of its subdirectories does not work. Eoi works
location = /robots.txt {
    proxy_pass http://static-server/$host/static/robots.txt;
  }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2019-08-27
@bozuriciyu

location /static/ {
    proxy_pass http://static-server/$host$uri;
}

Or
location /static/ {
    rewrite (.+) /$host$1 break;
    proxy_pass http://static-server;   
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question