我的目标是使用SSH隧道访问特定位置(即phpmyadmin),地址为http://localhost/phpmyadmin。
我刚安装了带有Nginx的Ubuntu 20.04。下面的配置在Ubuntu 18.04上运行良好。
我编辑了/etc/nginx/sites-available/default文件,添加了以下内容:
我刚安装了带有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 Forbidden nginx/1.17.10 (Ubuntu)
为了测试,我已经删除了 "deny all;",一切都正常工作,但每个ip地址都可以访问phpmyadmin位置。
nginx的错误日志:
2020/05/05 23:52:13 [error] 21905#21905: *1 access forbidden by rule, client: ::1, server: _, request: "GET /phpmyadmin/ HTTP/1.1", host: "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上这个配置不再起作用了吗?
location ^~ /phpmyadmin
。 - Dilson Rainovlocation ^~ /test {satisfy all; #需要满足两个条件allow 127.0.0.1; #仅允许本地主机拒绝所有其他来源}
,但结果仍然相同。 - Stevenginx -t
的结果是什么? - Dilson Rainov