mardi 20 mars 2018

nginx serve static files and run server on same host

Almost have this working how I want - basically I'm trying to serve static files on host/static (including directory listings), and serve to another backend for any non-file request (including the default site). The config below seems to do this, but the ONE problem remaining is that I can't get to the root static dir with host/static - a trailing slash is required! Any ideas?

My config:

location / {
  try_files /static/$uri /static/$uri/ @myserver;
}

location /static/ {
  alias /var/www/static_files/;
  autoindex on;
  disable_symlinks off;
}

location @myserver {
  proxy_pass              http://localhost:8081;
  proxy_set_header        Host $host;
  proxy_set_header        X-Real-IP $remote_addr;
  proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_connect_timeout   150;
  proxy_send_timeout      100;
  proxy_read_timeout      100;
  proxy_buffers           4 32k;
  client_max_body_size    8m;
  client_body_buffer_size 128k;
}




Aucun commentaire:

Enregistrer un commentaire