阅读量:2
在 Ubuntu 上,您可以使用 Nginx 或 Apache 作为 Web 服务器来限制对 PHP-FPM 的访问。这里我将为您提供两种方法:使用 Nginx 和使用 Apache。
方法1:使用 Nginx 限制访问
- 安装 Nginx(如果尚未安装):
sudo apt update
sudo apt install nginx
- 创建一个新的 Nginx 配置文件,或者编辑默认的配置文件。在这个例子中,我们将编辑默认的配置文件:
sudo nano /etc/nginx/sites-available/default
- 在
server块中,添加以下内容以限制对 PHP-FPM 的访问:
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; # 根据您的 PHP 版本更改
# 限制 IP 访问
allow 192.168.1.1; # 允许的 IP 地址
deny all; # 拒绝其他所有 IP 地址
# 限制用户访问
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
-
保存并退出编辑器。
-
重启 Nginx 以应用更改:
sudo systemctl restart nginx
方法2:使用 Apache 限制访问
- 安装 Apache(如果尚未安装):
sudo apt update
sudo apt install apache2
- 启用
mod_rewrite和mod_authz_core模块:
sudo a2enmod rewrite
sudo a2enmod authz_core
- 创建一个新的 Apache 配置文件,或者编辑默认的配置文件。在这个例子中,我们将编辑默认的配置文件:
sudo nano /etc/apache2/sites-available/000-default.conf
- 在
块中,添加以下内容以限制对 PHP-FPM 的访问:
Options FollowSymLinks
AllowOverride All
Require all granted
# 限制 IP 访问
Order Deny,Allow
Deny from all
Allow from 192.168.1.1 # 允许的 IP 地址
# 限制用户访问
Require user your_username
-
保存并退出编辑器。
-
重启 Apache 以应用更改:
sudo systemctl restart apache2
这样,您就可以根据 IP 地址或用户限制对 PHP-FPM 的访问了。请注意,您需要根据您的实际需求调整示例中的 IP 地址和用户名。
以上就是关于“php-fpm于ubuntu如何限制访问”的相关介绍,筋斗云是国内较早的云主机应用的服务商,拥有10余年行业经验,提供丰富的云服务器、租用服务器等相关产品服务。云服务器资源弹性伸缩,主机vCPU、内存性能强悍、超高I/O速度、故障秒级恢复;电子化备案,提交快速,专业团队7×24小时服务支持!
简单好用、高性价比云服务器租用链接:https://www.jindouyun.cn/product/cvm