A
A
Alexander Arbuzov2021-03-05 15:44:01
Nginx
Alexander Arbuzov, 2021-03-05 15:44:01

How to make nginx work with the framework from a folder for a specific location?

There is a directory on the site inside which the framework is deployed. I can’t target calls to the index.php of the framework in any way when called by the name of the directory in the url

/var/www/admin
  |-/public/
  |--index.php

It is also necessary that all routes be processed by the framework router. Those. so that the url of the view
Url - http://<ip>/admin/someone
is also processed by the
config framework at the moment
location ~ ^/admin/(.*) {
        index index.php;
        alias /var/www/admin/public;
        try_files $uri $uri/ /index.php?$args;
    }

With this configuration in the browser I get the error "File not found.", And in the logs "*416 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream" I've

already tried a lot of things, but nothing works. The maximum achieved is that the index is loaded not from the desired folder, but from the parent one.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2021-03-05
@arbuzzz

location ^~ /admin {
    root  /var/www/admin/public;

    rewrite ^/admin/(.*) /$1 break;

    try_files $uri /admin/index.php?$args;

    location ~ \.php$ {
        rewrite ^/admin/(.*) /$1 break;

        fastcgi_pass  php-fpm;
        include       fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question