我正在尝试使用Rob Van Aarle here描述的技巧在"不允许的路径中执行php页面"默认情况下,Synology的网络服务器......
目的是创建不依赖于" Init_3rdparty" (这个着名的软件包允许用户在/ synX / @ appstore /的Synology上运行php页面)
基本上,Rob建议使用php-cgi调用一个执行php页面的脚本(/ usr / local / bin / php56-cgi)
例如:调用这样的cgi来执行它旁边的页面test.php。
#!/bin/sh
REDIRECT_STATUS=1 export REDIRECT_STATUS
SCRIPT_FILENAME=$(pwd)/test.php export SCRIPT_FILENAME
/usr/bin/php-cgi -d open_basedir=none $SCRIPT_FILENAME 2>&1
这很好。
但Rob的完整想法是使用.htaccess将对任何php页面的调用重定向到通用cgi脚本。
的.htaccess
# Turn on rewrite engine.
RewriteEngine on
# Rewrite existing php files to the router script.
# Apache on the Synology NAS automatically redirects url
# containing '../' to the corresponding real path, before
# the router script is executed, so it's impossible to
# execute system files.
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*\.php)$ router.cgi [PT,L,QSA,NE]
router.cgi
#!/bin/sh
# Set redirect_status to 1 to get php cgi working.
REDIRECT_STATUS=1 export REDIRECT_STATUS
# Fix several $_SERVER globals.
PHP_SELF=$SCRIPT_URL export PHP_SELF
SCRIPT_NAME=$SCRIPT_URL export SCRIPT_NAME
# Strip web base from SCRIPT_URL, concat it to parent directory
# and apply realpath to construct absolute path to requested script.
WEB_BASE="/webman/3rdparty"
SCRIPT_FILENAME=$(pwd)/..${SCRIPT_URL:${#WEB_BASE}}
SCRIPT_FILENAME=`realpath $SCRIPT_FILENAME`
export SCRIPT_FILENAME
# Execute the requested PHP file.
/usr/local/bin/php56-cgi -d open_basedir=none $SCRIPT_FILENAME 2>&1
我在cgi中添加了跟踪,问题是它从未在我的DSM 6.1上调用过。所以,在我看来,.htaccess并没有启用"。具体来说,调用php页面正在下载该文件。
当DSM访问位于非允许路径中的php页面时,是否假定在Synology DSM 6.1上使用.htaccess?如果它应该可以工作,NAS上的配置可能是什么错误?
很多thx在adv。分享您的经验!
Rob创建的Here is the demo package来说明他的帖子。
答案 0 :(得分:0)
我终于弄明白了这个问题。最新版本的DSM默认使用nginx而不是apache作为Web服务器。而且nginx是not using htaccess files。