A
A
Alexander Smolin2017-06-14 09:56:01
Nginx
Alexander Smolin, 2017-06-14 09:56:01

How to rewrite a folder with a domain name in nginx?

There is a site on laravel which works on several domains.
The /srv/web/split/storage/markets folder contains sat resources. Since php will distribute these files much slower than an alias (rewrite) in nginx, you need to make this alias that gives files from /srv/web/split/storage/markets/$HOST/$FILEat $HOST/resources/$FILE. If this file does not exist, we give it from root (/srv/web/split/public)
Help organize this rewrite.
Site config at the moment:

server {
  listen 80;
  server_name domain1.ru domain2.ru domain3.ru domain4.ru;

  root /srv/web/split/public;
  index index.html index.php;

  location / {
    try_files $uri $uri/ /index.php?$query_string;
  }
}

Example:
aaa.hostname.ru/resources/app.min.css -> /srv/web/split/storage/markets/hostname.ru/app.min.css

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Livach, 2017-06-14
@Mausglov

location /resources/ {
    alias /srv/web/split/storage/markets/$host/;
}

I have no experience with $host - you may need to deploy your current config into 4 separate ones.
With the missing file, I think it should be solved via try_files $uri @named_location

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question