m5k1umn 发表于 2024-10-4 19:40:24

Nginx 是怎么禁止拜访php的 ?


    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;">商务合作加<span style="color: black;">微X</span>:2230304070&nbsp;</strong></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;"><span style="color: black;">学习与交流:</span></strong><a style="color: black;"><span style="color: black;"><strong style="color: blue;"><span style="color: black;">PHP技术交流<span style="color: black;">微X</span>群&nbsp;</span></strong></span></a></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;"><span style="color: black;">查看:</span></strong><strong style="color: blue;"><span style="color: black;"><a style="color: black;">JetBrains<span style="color: black;">整家</span>桶<span style="color: black;">长时间</span><span style="color: black;">守护</span>的个人账号 一次加入 永久<span style="color: black;">运用</span></a></span></strong></span></p>禁止<span style="color: black;">拜访</span> PHP 脚本<span style="color: black;">能够</span><span style="color: black;">经过</span> Nginx 服务器配置中的多种方式来实现。以下是其中的<span style="color: black;">有些</span><span style="color: black;">平常</span><span style="color: black;">办法</span>,您<span style="color: black;">能够</span><span style="color: black;">按照</span><span style="color: black;">实质</span><span style="color: black;">需要</span><span style="color: black;">选取</span>合适的方式:1 <strong style="color: blue;">禁用 PHP 解析:</strong>在 Nginx 配置中,<span style="color: black;">保证</span> PHP 脚本<span style="color: black;">没法</span>被解析,从而禁止 PHP 执行。<span style="color: black;">location</span>&nbsp;<span style="color: black;">~&nbsp;\.php$</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">&nbsp;{</p>&nbsp;&nbsp;&nbsp;<span style="color: black;">deny</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">&nbsp;all;</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">}</p>2 <strong style="color: blue;">限制<span style="color: black;">拜访</span>路径:</strong>限制只<span style="color: black;">准许</span><span style="color: black;">拜访</span>特定路径下的 PHP 脚本,其他路径禁止。<span style="color: black;">location</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">&nbsp;/public&nbsp;{</p>&nbsp;&nbsp;&nbsp;<span style="color: black;">#&nbsp;<span style="color: black;">准许</span><span style="color: black;">拜访</span>&nbsp;/public&nbsp;下的&nbsp;PHP&nbsp;脚本</span>&nbsp;&nbsp;&nbsp;<span style="color: black;">location</span>&nbsp;<span style="color: black;">~&nbsp;\.php$</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">&nbsp;{</p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: black;">fastcgi_pass</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">&nbsp;unix:/var/run/php-fpm.sock;</p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: black;">include</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">&nbsp;fastcgi_params;</p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: black;">fastcgi_param</span>&nbsp;SCRIPT_FILENAME&nbsp;<span style="color: black;">$document_root</span><span style="color: black;">$fastcgi_script_name</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">;</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">&nbsp;&nbsp;&nbsp;}</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">}</p><span style="color: black;">#&nbsp;禁止<span style="color: black;">拜访</span>其他路径的&nbsp;PHP&nbsp;脚本</span><span style="color: black;">location</span>&nbsp;<span style="color: black;">~&nbsp;\.php$</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">&nbsp;{</p>&nbsp;&nbsp;&nbsp;<span style="color: black;">deny</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">&nbsp;all;</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">}</p>3 <strong style="color: blue;"><span style="color: black;">运用</span> HTTP Basic 认证:</strong><span style="color: black;">需求</span>用户<span style="color: black;">供给</span>用户名和<span style="color: black;">秘码</span>以<span style="color: black;">拜访</span> PHP 脚本。<span style="color: black;">location</span>&nbsp;<span style="color: black;">~&nbsp;\.php$</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">&nbsp;{</p>&nbsp;&nbsp;&nbsp;<span style="color: black;">auth_basic</span>&nbsp;<span style="color: black;">"Restricted"</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">;</p>&nbsp;&nbsp;&nbsp;<span style="color: black;">auth_basic_user_file</span>&nbsp;/etc/nginx/.htpasswd;&nbsp;<span style="color: black;">#&nbsp;使用&nbsp;htpasswd&nbsp;生成<span style="color: black;">秘码</span>文件</span>&nbsp;&nbsp;&nbsp;<span style="color: black;">#&nbsp;...</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">}</p>4 <strong style="color: blue;">IP <span style="color: black;">位置</span><span style="color: black;">拜访</span><span style="color: black;">掌控</span>:</strong>限制<span style="color: black;">仅有</span>特定的 IP <span style="color: black;">位置</span><span style="color: black;">能够</span><span style="color: black;">拜访</span> PHP 脚本。<span style="color: black;">location</span>&nbsp;<span style="color: black;">~&nbsp;\.php$</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">&nbsp;{</p>&nbsp;&nbsp;&nbsp;<span style="color: black;">allow</span>&nbsp;<span style="color: black;">192.168.1.1</span>;&nbsp;<span style="color: black;">#&nbsp;<span style="color: black;">准许</span>的&nbsp;IP&nbsp;<span style="color: black;">位置</span></span>&nbsp;&nbsp;&nbsp;<span style="color: black;">deny</span>&nbsp;all;&nbsp;<span style="color: black;">#&nbsp;禁止其他&nbsp;IP&nbsp;<span style="color: black;">位置</span></span>&nbsp;&nbsp;&nbsp;<span style="color: black;">#&nbsp;...</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">}</p>5 <strong style="color: blue;">Referer <span style="color: black;">检测</span>:</strong><span style="color: black;">检测</span> HTTP Referer 头,只<span style="color: black;">准许</span>特定<span style="color: black;">源自</span>的请求。<span style="color: black;">location</span>&nbsp;<span style="color: black;">~&nbsp;\.php$</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">&nbsp;{</p>&nbsp;&nbsp;&nbsp;<span style="color: black;">valid_referers</span>&nbsp;<span style="color: black;">none</span>&nbsp;<span style="color: black;">blocked</span>&nbsp;example.com;&nbsp;<span style="color: black;">#&nbsp;<span style="color: black;">准许</span>的&nbsp;Referer</span>&nbsp;&nbsp;&nbsp;<span style="color: black;">if</span>&nbsp;(<span style="color: black;">$invalid_referer</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">)&nbsp;{</p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: black;">return</span>&nbsp;<span style="color: black;">403</span>;&nbsp;<span style="color: black;">#&nbsp;拒绝无效的&nbsp;Referer</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">&nbsp;&nbsp;&nbsp;}</p>&nbsp;&nbsp;&nbsp;<span style="color: black;">#&nbsp;...</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">}</p>6 <strong style="color: blue;">User-Agent <span style="color: black;">检测</span>:</strong><span style="color: black;">检测</span> User-Agent 头,只<span style="color: black;">准许</span>特定 User-Agent <span style="color: black;">拜访</span>。<span style="color: black;">location</span>&nbsp;<span style="color: black;">~&nbsp;\.php$</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">&nbsp;{</p>&nbsp;&nbsp;&nbsp;<span style="color: black;">if</span>&nbsp;(<span style="color: black;">$http_user_agent</span>&nbsp;<span style="color: black;">~*&nbsp;(bad-agent|another-bad-agent))</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">&nbsp;{</p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: black;">return</span>&nbsp;<span style="color: black;">403</span>;&nbsp;<span style="color: black;">#&nbsp;拒绝不良&nbsp;User-Agent</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">&nbsp;&nbsp;&nbsp;}</p>&nbsp;&nbsp;&nbsp;<span style="color: black;">#&nbsp;...</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">}</p>7 <strong style="color: blue;">URL 匹配:</strong><span style="color: black;">经过</span>正则表达式匹配 URL,只<span style="color: black;">准许</span>特定 URL <span style="color: black;">拜访</span> PHP。<span style="color: black;">location</span>&nbsp;<span style="color: black;">~&nbsp;\.php$</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">&nbsp;{</p>&nbsp;&nbsp;&nbsp;<span style="color: black;">if</span>&nbsp;(<span style="color: black;">$request_uri</span>&nbsp;<span style="color: black;">~*&nbsp;^/allowed-path/)</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">&nbsp;{</p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: black;">#&nbsp;<span style="color: black;">准许</span>的&nbsp;URL&nbsp;路径</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: black;">#&nbsp;...</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">&nbsp;&nbsp;&nbsp;}</p>&nbsp;&nbsp;&nbsp;<span style="color: black;">return</span>&nbsp;<span style="color: black;">403</span>;&nbsp;<span style="color: black;">#&nbsp;其他路径禁止</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">}</p>8 <strong style="color: blue;">文件类型匹配:</strong>只<span style="color: black;">准许</span>特定文件类型的 PHP 文件执行。<span style="color: black;">location</span>&nbsp;<span style="color: black;">~&nbsp;\.php$</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">&nbsp;{</p>&nbsp;&nbsp;&nbsp;<span style="color: black;">if</span>&nbsp;(<span style="color: black;">$request_filename</span>&nbsp;<span style="color: black;">~*&nbsp;\.php$)</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">&nbsp;{</p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: black;">#&nbsp;<span style="color: black;">准许</span>的文件类型</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: black;">#&nbsp;...</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">&nbsp;&nbsp;&nbsp;}</p>&nbsp;&nbsp;&nbsp;<span style="color: black;">return</span>&nbsp;<span style="color: black;">403</span>;&nbsp;<span style="color: black;">#&nbsp;禁止其他文件类型</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">}</p>9 <strong style="color: blue;">设置文件权限:</strong><span style="color: black;">经过</span>文件系统的权限设置,限制 PHP 脚本的<span style="color: black;">拜访</span>。<span style="color: black;">location</span>&nbsp;<span style="color: black;">~&nbsp;\.php$</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">&nbsp;{</p>&nbsp;&nbsp;&nbsp;<span style="color: black;">#&nbsp;设置文件的<span style="color: black;">拜访</span>权限为&nbsp;600&nbsp;或更高</span>&nbsp;&nbsp;&nbsp;<span style="color: black;">#&nbsp;...</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">}</p>10 <strong style="color: blue;">利用 Nginx 的 map 模块:</strong><span style="color: black;">运用</span> Nginx 的 map 模块来<span style="color: black;">按照</span><span style="color: black;">要求</span>禁止 PHP <span style="color: black;">拜访</span>。<span style="color: black;">map</span>&nbsp;<span style="color: black;">$remote_addr</span>&nbsp;<span style="color: black;">$php_disabled</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">&nbsp;{</p>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: black;">default</span>&nbsp;<span style="color: black;">0</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">;</p>&nbsp;&nbsp;&nbsp;&nbsp;192.168.1.1&nbsp;0;&nbsp;<span style="color: black;">#&nbsp;<span style="color: black;">准许</span>的&nbsp;IP&nbsp;<span style="color: black;">位置</span></span>&nbsp;&nbsp;&nbsp;&nbsp;~^192\.168\.2\.&nbsp;1;&nbsp;<span style="color: black;">#&nbsp;<span style="color: black;">准许</span>的&nbsp;IP&nbsp;<span style="color: black;">位置</span>范围</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">}</p><span style="color: black;">location</span>&nbsp;<span style="color: black;">~&nbsp;\.php$</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">&nbsp;{</p>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: black;">if</span>&nbsp;(<span style="color: black;">$php_disabled</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">)&nbsp;{</p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: black;">return</span>&nbsp;<span style="color: black;">403</span>;&nbsp;<span style="color: black;">#&nbsp;禁止<span style="color: black;">拜访</span></span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">&nbsp;&nbsp;&nbsp;&nbsp;}</p>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: black;">#&nbsp;...</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">}</p>11 <strong style="color: blue;">利用 Nginx 的 geo 模块:</strong><span style="color: black;">运用</span> Nginx 的 geo 模块<span style="color: black;">按照</span>地理位置禁止 PHP <span style="color: black;">拜访</span>。<span style="color: black;">geo</span>&nbsp;<span style="color: black;">$allowed_country</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">&nbsp;{</p>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: black;">default</span>&nbsp;<span style="color: black;">0</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">;</p>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: black;">US</span>&nbsp;<span style="color: black;">1</span>;&nbsp;<span style="color: black;">#&nbsp;<span style="color: black;">准许</span>的国家或地区</span>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: black;">CA</span>&nbsp;<span style="color: black;">1</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">;</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">}</p><span style="color: black;">location</span>&nbsp;<span style="color: black;">~&nbsp;\.php$</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">&nbsp;{</p>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: black;">if</span>&nbsp;(<span style="color: black;">$allowed_country</span>&nbsp;=&nbsp;<span style="color: black;">0</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">)&nbsp;{</p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: black;">return</span>&nbsp;<span style="color: black;">403</span>;&nbsp;<span style="color: black;">#&nbsp;禁止<span style="color: black;">拜访</span></span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">&nbsp;&nbsp;&nbsp;&nbsp;}</p>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: black;">#&nbsp;...</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">}</p>12 <strong style="color: blue;">禁止特定 HTTP <span style="color: black;">办法</span>:</strong>限制<span style="color: black;">仅有</span>特定的 HTTP <span style="color: black;">办法</span><span style="color: black;">能够</span><span style="color: black;">拜访</span> PHP 脚本。<span style="color: black;">location</span>&nbsp;<span style="color: black;">~&nbsp;\.php$</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">&nbsp;{</p>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: black;">if</span>&nbsp;(<span style="color: black;">$request_method</span>&nbsp;!<span style="color: black;">~&nbsp;^(GET|POST)$)</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">&nbsp;{</p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: black;">return</span>&nbsp;<span style="color: black;">403</span>;&nbsp;<span style="color: black;">#&nbsp;禁止其他<span style="color: black;">办法</span></span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">&nbsp;&nbsp;&nbsp;&nbsp;}</p>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: black;">#&nbsp;...</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">}</p>13 <strong style="color: blue;">限制<span style="color: black;">拜访</span>时间:</strong>限制<span style="color: black;">仅有</span>在特<span style="color: black;">按时</span>间段内<span style="color: black;">能够</span><span style="color: black;">拜访</span> PHP 脚本。<span style="color: black;">location</span>&nbsp;<span style="color: black;">~&nbsp;\.php$</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">&nbsp;{</p>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: black;">if</span>&nbsp;(<span style="color: black;">$time_iso8601</span>&nbsp;!<span style="color: black;">~&nbsp;"T(08|09|10|11|12|13):")</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">&nbsp;{</p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: black;">return</span>&nbsp;<span style="color: black;">403</span>;&nbsp;<span style="color: black;">#&nbsp;限制<span style="color: black;">拜访</span>时段</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">&nbsp;&nbsp;&nbsp;&nbsp;}</p>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: black;">#&nbsp;...</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">}</p>14 <strong style="color: blue;">HTTP <span style="color: black;">拜访</span>速率限制:</strong>限制<span style="color: black;">拜访</span>速率以减轻服务器负载。<span style="color: black;">location</span>&nbsp;<span style="color: black;">~&nbsp;\.php$</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">&nbsp;{</p>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: black;">limit_req</span>&nbsp;zone=mylimit&nbsp;burst=<span style="color: black;">5</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">&nbsp;nodelay;</p>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: black;">limit_req_status</span>&nbsp;<span style="color: black;">403</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">;</p>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: black;">#&nbsp;...</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">}</p>15 <strong style="color: blue;"><span style="color: black;">运用</span> Nginx 内置变量:</strong><span style="color: black;">运用</span> Nginx 的内置变量结合<span style="color: black;">要求</span>语句来<span style="color: black;">按照</span>特定<span style="color: black;">要求</span>禁止 PHP <span style="color: black;">拜访</span>。<span style="color: black;">location</span>&nbsp;<span style="color: black;">~&nbsp;\.php$</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">&nbsp;{</p>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: black;">if</span>&nbsp;(<span style="color: black;">$http_cookie</span>&nbsp;<span style="color: black;">~*&nbsp;"adminuser=")</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">&nbsp;{</p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: black;">return</span>&nbsp;<span style="color: black;">403</span>;&nbsp;<span style="color: black;">#&nbsp;<span style="color: black;">倘若</span><span style="color: black;">包括</span>特定&nbsp;Cookie</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">&nbsp;&nbsp;&nbsp;&nbsp;}</p>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: black;">#&nbsp;...</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">}</p>请<span style="color: black;">重视</span>,<span style="color: black;">以上</span><span style="color: black;">办法</span><span style="color: black;">能够</span>单独<span style="color: black;">运用</span>或组合<span style="color: black;">运用</span>,<span style="color: black;">详细</span>的<span style="color: black;">选取</span>取决于您的安全<span style="color: black;">需要</span>和服务器配置。<span style="color: black;">同期</span>,<span style="color: black;">保证</span>在配置中<span style="color: black;">运用</span>适当的测试和调试<span style="color: black;">办法</span>,以<span style="color: black;">保证</span>您的 Nginx 服务器<span style="color: black;">根据</span>预期运行。<h1 style="color: black; text-align: left; margin-bottom: 10px;"><strong style="color: blue;">JetBrains<span style="color: black;">整家</span>桶<span style="color: black;">长时间</span><span style="color: black;">守护</span>的个人账号 一次加入 永久<span style="color: black;">运用</span></strong></h1><strong style="color: blue;"><a style="color: black;"><span style="color: black;"><img src="https://mmbiz.qpic.cn/mmbiz_png/QibLP1rpwH8upyC9IjyOBpSU4ON2WUkL6ic3WVxYN00mWZ63lrB8CDJhYeZdMbOcqRP2hbjaZjAebwHCqkMia8GPA/640?wx_fmt=png&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1&amp;tp=webp" style="width: 50%; margin-bottom: 20px;"></span></a></strong><img src="https://mmbiz.qpic.cn/mmbiz_gif/X36HLl2EicOfbCTTtzwpbdicOhvibmKu9O9jGSLPicT5IVjk2U8YETibumKAAa5K55Y3mdvGOvhjfbUGdEibKx8E5BJQ/640?wx_fmt=gif&amp;wxfrom=5&amp;wx_lazy=1&amp;tp=webp" style="width: 50%; margin-bottom: 20px;"><span style="color: black;"><strong style="color: blue;"><span style="color: black;">参考链接:</span></strong></span><span style="color: black;"><span style="color: black;">以上<span style="color: black;">便是</span>本篇分钟的<span style="color: black;">所有</span>内容,</span><span style="color: black;"><strong style="color: blue;"><span style="color: black;"><span style="color: black;">期盼</span>各位程序员们<span style="color: black;">奋斗</span><span style="color: black;">提高</span>个人技术。</span></strong></span><span style="color: black;">最后,<span style="color: black;">博主</span>温馨提示:<span style="color: black;">每日</span>阅读5分钟,<span style="color: black;">每日</span>学习一点点,<span style="color: black;">每日</span>进步一点点。</span></span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="https://mmbiz.qpic.cn/mmbiz_gif/X36HLl2EicOfSLeDjYdhheic53iaMxy6jzuQaBEXzfu12r8KsocY8g1D5GGfcUJ4nibr37JY3ZZBu1wjKiaNxEASXUA/640?wx_fmt=gif&amp;wxfrom=5&amp;wx_lazy=1&amp;tp=webp" style="width: 50%; margin-bottom: 20px;"></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><img src="https://mmbiz.qpic.cn/mmbiz_jpg/uIqA9zdyleyDIhxfbt7DaTT5a4QibDoG9cjrINXv1wpUImSribq2abGGGYeN0j5tsgJ6yQBytrXmUFprtSOA4Ceg/640?wx_fmt=other&amp;tp=webp&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" style="width: 50%; margin-bottom: 20px;">‍</span></span></p>




wrjc1hod 发表于 2024-10-17 23:50:44

楼主发的这篇帖子,我觉得非常有道理。

wrjc1hod 发表于 2024-10-23 18:34:51

论坛的成果是显著的,但我们不能因为成绩而沾沾自喜。

1fy07h 发表于 6 天前

在遇到你之前,我对人世间是否有真正的圣人是怀疑的。

j8typz 发表于 昨天 06:02

祝福你、祝你幸福、早日实现等。
页: [1]
查看完整版本: Nginx 是怎么禁止拜访php的 ?