H
H
hckn2018-08-04 19:16:42
Nginx
hckn, 2018-08-04 19:16:42

How to fix a route conflict?

upstream api {
  server 127.0.0.1:7777;
}

server {
  listen 80;
  listen [::]:80;
  server_name example.com;

  root /home/iam/project/dist;

  location / {
    try_files $uri $uri/ /index.html;
  }

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

  location /static/ {
    alias /home/iam/cdn/uploads/;
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }
}

The problem is that there root /home/iam/project/distis also a folder statichere!
How to fix it? Leaving the route/static/

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dodo512, 2018-08-04
@dodo512

upstream api {
  server 127.0.0.1:7777;
}

server {
  listen 80;
  listen [::]:80;
  server_name example.com;

  root /home/iam/project/dist;

  location / {
    try_files $uri $uri/ /index.html;
  }

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

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

  location @cdn_uploads {
    root /home/iam/cdn/uploads;
    rewrite ^/static(/.*)$  $1 break;
  }
}

K
ky0, 2018-08-04
@ky0

Please specify what is the problem? If you want different locations to look in different directories, set different root`s for them.
Z.Y. - you know why you put trailing slashes in directives, right?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question