3

我的目标是使用 SSH 隧道http://localhost/phpmyadmin访问特定位置(即 phpmyadmin)

我刚刚用 Nginx 安装了 Ubuntu 20.04。以下配置在 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)

只是为了测试,我删除了“全部拒绝”;一切正常,但每个 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 吗?

4

1 回答 1

3

您也需要允许 ::1 ...并在 location 块中添加 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;
    }


}
于 2020-05-05T20:57:42.170 回答