H
H
Hazrat Hajikerimov2019-05-12 16:37:05
Nginx
Hazrat Hajikerimov, 2019-05-12 16:37:05

Nginx: How to serve another file?

Greetings, if there is a specific host in the $http_referer variable, it is necessary to give another html file, namely to give and not a redirect to another file.
Now this is not working:

server {
  listen 80 default_server;
  listen 443 default_server;
  server_name example.com www.example.com;
  root /var/www/example.com;
  index index.html;

  error_log /dev/null crit;
  access_log off;

  location / {
    if ($http_referer ~ 'http://google.ru/apps/') {
      rewrite ^ apps/index.html last;
    }
    try_files $uri $uri/ /index.html;
  }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Mukovoz, 2019-05-12
@castomi

nginx.org/ru/docs/http/ngx_http_core_module.html#t...
https://nginx.org/ru/docs/http/ngx_http_map_module...

map $http_referer $index {
 default $uri;
 '~http://google.ru/apps/' '/apps/index.html';
}
try_files $index $uri $uri/ /index.html;

Well, somehow)
We read the docks before use and correct for ourselves.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question