Nginx 403 Запрещено для location и localhost - PullRequest
1 голос
/ 05 мая 2020

Моя цель - получить доступ к указанному c местоположению (т.е. phpmyadmin) с помощью туннеля S SH http://localhost/phpmyadmin

Я только что установил Ubuntu 20.04 с Nginx. Следующая конфигурация отлично работала с Ubuntu 18.04.

Я редактировал / etc / nginx / sites-available / default, добавляя:

  location /phpmyadmin {
    #Allow localhost
    allow 127.0.0.1;
    #deny all the others ip
    deny all;
  }

при доступе к http://localhost/phpmyadmin Я получаю сообщение об ошибке:

403 Запрещено nginx / 1.17.10 (Ubuntu)

Просто для тестирования я удалил "deny all;" все работает нормально, но каждый IP-адрес может получить доступ к местоположению phpmyadmin.

журнал ошибок nginx:

2020/05/05 23:52:13 [ошибка] 21905 # 21905: * 1 доступ запрещен правилом, клиент: :: 1, сервер: _, запрос: «GET / phpmyadmin / HTTP / 1.1», хост: «localhost»

server {
    listen 80 default_server;
    listen [::]:80 default_server;


    root /var/www/html;

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

    server_name _;

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

   # pass PHP scripts to FastCGI server
    #
    location ~ \.php$ {
            include snippets/fastcgi-php.conf;

            # With php-fpm (or other unix sockets):
            fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
            # With php-cgi (or other tcp sockets):
            #fastcgi_pass 127.0.0.1:9000;
    }


location /phpmyadmin {
    satisfy all;
    allow 127.0.0.1;
    deny all;
    }


   }

Есть идеи, почему эта конфигурация больше не работает с ubuntu 20.04 и nginx 1.17.10?

1 Ответ

1 голос
/ 05 мая 2020

Вам также необходимо разрешить :: 1 ... И добавить параметры для php внутри блока местоположения.

Попробуйте вот так

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /var/www/html;

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

    server_name _;

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

   # pass PHP scripts to FastCGI server
    #
    location ~ \.php$ {
            include snippets/fastcgi-php.conf;

            # With php-fpm (or other unix sockets):
            fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
            # With php-cgi (or other tcp sockets):
            #fastcgi_pass 127.0.0.1:9000;
    }


    location ^~ /phpmyadmin/ {
            allow 127.0.0.1;
            allow ::1;
            deny all;
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
    }


}
...