nginx не запускает php по местоположению

Я должен получить phppgadmin от example.com/phppgadmin, но что-то идет не так. Я мог бы получить это по example.com/ (см. комментарии в конф. ниже). Но если я пытаюсь получить phppgadmin создавая locationв конфиге nginx я получаю 404 not found, Что я делаю неправильно? Error.log Это хорошо.

Здесь nginx конф:

server {

        listen 80 default_server;
        listen [::]:80 default_server;

        # Add index.php to the list if you are using PHP
        index index.php index.html index.htm index.nginx-debian.html;

        server_name example.com;

        #This path works. We are getting phppgadmin by example.com/ , 
        #but I need to get it by location (example.com/phppgadmin):
        #root /usr/share/phppgadmin;

        #This should work but it doesn't:
        location /phppgadmin/ {  

        root /usr/share;

        }

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }

        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
                include fastcgi_params;
        }
}

1 ответ

Если вы разместите root /usr/share; в server блок (где оригинал root выписка была), URI example.com/phppgadmin/ будет работать как ожидалось.

Но это также раскрыло бы все содержание /usr/share каталог, который вы можете не захотеть.

Вы можете разместить root заявление внутри location но вам нужно включить все директивы, необходимые для обработки запроса.

Например:

location ^~ /phppgadmin/ {  
    root /usr/share;
    try_files $uri $uri/ =404;

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        include fastcgi_params;
    }
}

^~ Модификатор позволяет избежать двусмысленности с URI, заканчивающимися на .php, Смотрите этот документ для деталей.

Другие вопросы по тегам