如何授予服务器访问php文件的权限,而其他服务器不能?
我已经在如何授予服务器访问php文件的权限,而其他服务器不能?,php,apache,.htaccess,permissions,ubuntu-18.04,Php,Apache,.htaccess,Permissions,Ubuntu 18.04,我已经在.htaccess项目根目录下的文件中添加了以下内容: <Files *.php> Require host lamtakam.test lamtakam.com Require ip ::1 95.216.xx.xx </Files> 但我得到了这个错误: --2020-09-13 13:33:55-- https://lamtakam.com/path/to/file.php Resolving lamtakam.com (lamtakam
.htaccess
项目根目录下的文件中添加了以下内容:
<Files *.php>
Require host lamtakam.test lamtakam.com
Require ip ::1 95.216.xx.xx
</Files>
但我得到了这个错误:
--2020-09-13 13:33:55-- https://lamtakam.com/path/to/file.php
Resolving lamtakam.com (lamtakam.com)... 104.31.74.192, 172.67.174.239, 104.31.75.192, ...
Connecting to lamtakam.com (lamtakam.com)|104.31.74.192|:443... connected.
HTTP request sent, awaiting response... 403 Forbidden
2020-09-13 13:33:55 ERROR 403: Forbidden.
注意:我使用Cloudflare,这些IP属于它:104.31.74.192、172.67.174.239、104.31.75.192
当我可以从同一台服务器访问
file.php
时,你知道如何让它可以访问吗?(而不是从其他任何地方)您可以在crontab中这样使用curl
:
curl -k https://localhost/path/to/file.php'
或:
根据man grep:
-k,--unsecure
(TLS)默认情况下,curl建立的每个SSL连接都被验证为安全的。此选项允许curl继续运行,即使对于服务器也是如此
否则被认为是不安全的连接
并通过允许IP:127.0.0.1
和主机:localhost
来修改文件
指令:
<Files *.php>
Require host localhost lamtakam.test lamtakam.com
Require ip ::1 127.0.0.1 95.216.xx.xx
</Files>
需要主机localhost lamtakam.test lamtakam.com
需要ip::1 127.0.0.1 95.216.xx.xx
@anubhava当我直接调用该文件时,它抛出错误:PHP致命错误:require_once():在/var/www/…
中打开required'../../config.PHP'(include_path=.:/usr/share/PHP')失败。这就是为什么我将其称为https request.emm。。你的确切意思是什么@anubhavaI的意思是使用wgethttps://localhost/path/to/file.php
@anubhava它抛出解析本地主机(localhost)。。。127.0.0.1连接到本地主机(localhost)| 127.0.0.1 |:443。。。有联系的。错误:没有与请求的主机名“localhost”匹配的证书使用者备选名称。要不安全地连接到本地主机,请使用--no check certificate.
问题已解决@anubhava,谢谢。。(注意,我认为::1
可以作为127.0.0.1
的替代方案,但我错了)我是这样写的Require ip::1 127.0.0.1 95.216.xx.xx
而不是有两个Require ip
的,它看起来很有效。有什么评论吗?
curl --insecure https://localhost/path/to/file.php
<Files *.php>
Require host localhost lamtakam.test lamtakam.com
Require ip ::1 127.0.0.1 95.216.xx.xx
</Files>