phpMyAdmin怎么设置只允许特定ip访问
发布日期:
作者: 西木
评论数:暂无评论
1. 如果Web服务器是Nginx
打开你网站的 Nginx 配置文件,举例:
sudo vi /etc/nginx/sites-available/default
在 phpMyAdmin 的 location
块中添加以下内容
location /phpmyadmin {
allow 192.168.1.2; # 替换为第一个允许访问的 IP 地址
allow 192.168.1.3; # 替换为第二个允许访问的 IP 地址
allow 192.168.0.0/24; # 替换为允许的ip段
deny all;
}
配置说明:
allow
指令:- 每个 IP 地址对应一个
allow
。 - 只需在配置中按行添加多个
allow
即可。
- 每个 IP 地址对应一个
deny all
指令:- 用于拒绝所有不在
allow
列表中的 IP 地址。 - 必须写在所有
allow
指令之后。
- 用于拒绝所有不在
保存后,重启 Nginx 后生效:
sudo systemctl restart nginx
这是www.ximu.work的隐形间隔
2. 如果Web服务器是Apache
可以通过 Apache 的 Require
指令限制访问路径。
编辑配置文件:
sudo vi /etc/apache2/conf-available/phpmyadmin.conf
为 phpMyAdmin 的路径添加 IP 限制规则。例如:
<Directory /usr/share/phpmyadmin>
Options FollowSymLinks
DirectoryIndex index.php
# 限制访问,仅允许特定的 IP
Require ip 192.168.1.2
Require ip 192.168.1.3
Require ip 192.168.0.0/24
Require all denied
.............
</Directory>
配置说明:
Require ip
:- 允许特定 IP 地址访问。将里面的ip替换为你允许访问的 IP 地址
Require all denied
:- 拒绝所有其他 IP。
保存后,重启 Apache 生效
sudo systemctl restart apache2