V
V
Vasily Alibabaevich2015-07-09 07:57:32
linux
Vasily Alibabaevich, 2015-07-09 07:57:32

How to make a unique link (location, nginx)?

I want nginx to work at the link test.ru/m01 as follows:

  • made the following folder the root directory: new
  • the index file was file.html

It is assumed that m can be from m01 to m60. There are no such folders on the server, and it is not necessary. I made a regular.
location / {
                        if ($host != 'test.ru'){
                        rewrite (.*) http://test.ru$1   permanent;
                        }
                         if ($request_uri ~ /m01$) {
                         set $root_path $root_path/new;
                         set $index file.html;
                         root $root_path;
                         rewrite ^/(m01)$ /$1/file.html;
                         }
                         root $root_path;
                         index $index;

But, the logs say this: *1 open() "/var/www/test.ru/new/new/m01/file.html" failed (2: No such file or directory)
What I'm doing wrong and how it should be SO ?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
Lynn "Coffee Man", 2015-07-09
@dimitrius86

> What I'm doing wrong
About everything.

server {
  listen 80 default_server;
  return 301 http://test.ru$request_uri;
}

server {
  listen 80;
  server_name test.ru;
  root /path/to/root;

  rewrite ^/m[0-6][0-9]$ /new/file.html;

  ...
}

D
DigitalSmile, 2015-07-09
@DigitalSmile

What am I doing wrong

wiki.nginx.org/IfIsEvil
There are also examples of how to do this.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question