M
M
Michael2018-06-13 13:24:41
PHP
Michael, 2018-06-13 13:24:41

How to fix Nginx config for phpmyadmin to work?

Preface)
The essence of the question is as follows, there is a working server on nginx, which was assembled for tests on desktop ubuntu 16.04, having debugged all the work on it, before transferring it to production, I decided to rebuild the server already on the server version of the same ubuntu 16.04. This is where the differences end, otherwise the configuration configs and package versions are identical...
The situation is as follows: when you go to the domain/phpmyadmin address, an authorization window opens, after pressing the OK button on the assembled server, a problem is revealed in the form that the request is redirected to the site index ( as I understand it, but this is not accurate) instead of going to the DBMS index. That is, in the address bar we see this
192.168.0.53/index.php?token=35a415ef8c8cac6fe8cf1...
On the initial build, this does not happen, although the configs are identical... In the second case, during normal processing, the address looks like this: 192.168.83.53 /phpmyadmin/index.php?token=0ca9ef776d87ec33704959d69fad204d " /
phpmyadmin/" disappears somewhere from the request...
I put the default config here:

spoiler
server {
  listen 80;
  root /var/www/html/delc.laravel/public;
  index index.php index.html;
  server_name delc.laravel www.delc.laravel;

  location /{
    try_files $uri $uri/ /index.php?$query_string;
  }
  location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
  }

  #phpMyAdmin
  
  location /phpmyadmin {
  root /usr/share/;
  index index.php;
  try_files $uri $uri/ =404;
  
  location ~ /phpmyadmin/(doc|sql|setup)/ {
    deny all;
  }
  
  location ~ /phpmyadmin/(.+\.php)$ {
    fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    include snippets/fastcgi-php.conf;
  }}



  location ~ /\.ht {
    deny all;
  }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yuri, 2018-06-19
@TaHKucT

location can be specified as a prefix string or as a regular expression. Regular expressions are specified either with the “~*” modifier (to search for a case-insensitive match), or with the “~” modifier (case-sensitive). To find a location that matches the query, the locations given by prefix strings (prefix locations) are first checked. Among them, a location with a matching prefix of the maximum length is searched and remembered. The regular expressions are then checked, in the order in which they appear in the configuration file. Regular expression checking stops after the first match, and the appropriate configuration is used. If no match is found for the regular expression, then the configuration of the previously stored prefix location is used.

https://nginx.ru/ru/docs/http/ngx_http_core_module...
Most likely, the request to phpmyadmin/index.php goes not to "location ~ /phpmyadmin/(.+\.php)$", but to "location ~ \.php$" (because the first match is for location with a regular expression).
Look either here (recommendations directly from Igor Sysoev on writing configs) or here (there is a direct example of a config for a site that lies at its root address and phpmyadmin at its root address).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question