E
E
Eugene2017-04-20 13:02:32
Nginx
Eugene, 2017-04-20 13:02:32

How to override root in NGINX?

There is a site with the structure:
admin/
- controllers/
- index.php (entry point to the admin panel, handles routing)
index.html
current config:

server {
  listen 80;
  server_name project.local

  location / {
    index index.php;
    root /home/user/Sites/project/;
    try_files $uri $uri/ /admin/index.php;

    location ~* \.php {
        include fastcgi_params;
        fastcgi_pass unix:/run/php/php7.1-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    location ^~ /admin/* {
      index index.php;
      root /home/user/Sites/project/admin/;
      try_files $uri $uri/ /admin/index.php;
    }
  }
}

The task is to make it possible for several sites to work with one admin panel. I'm thinking, for example, to create the following structure:
admin/
- controllers/
- index.php (entry point to the admin panel, does routing)
sites/
- site1/
- - index.html
- site2/
- - index.html
and make your own for each site nginx config and, accordingly, change the root of each to
root /home/user/Sites/project/sites/site1

but at the same time I can’t get the admin section to work, I’ve been fighting for the 3rd day already, I tried different settings, I need help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wexter, 2017-04-20
@djtahoma

location ^~ /admin {
      index index.php;
      root /home/user/Sites/project/;
      try_files $uri $uri/ /admin/index.php;
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question