简体   繁体   English

如何在Synology / DSM 6.1的非基于openir的路径中使用.htaccess

[英]How to use .htaccess in a non open-basedir path of Synology/DSM 6.1

I am trying to use the trick described by Rob Van Aarle here to execute php pages in "paths not allowed" by default for Synology's web server... 我正在尝试使用Rob Van Aarle 在此处描述的技巧,默认情况下对Synology的Web服务器执行“不允许的路径”中的php页面...

The purpose is to create packages which do not depend on " Init_3rdparty " (this famous package which allows users to run php pages in path like /volumeX/@appstore/ on their Synology) 目的是创建不依赖于“ Init_3rdparty ”的软件包(此著名的软件包允许用户在其Synology上的/ volumeX / @ appstore /之类的路径中运行php页面)

Basically, Rob suggests to call a script which execute the php page using php-cgi (/usr/local/bin/php56-cgi) 基本上,Rob建议使用php-cgi(/ usr / local / bin / php56-cgi)调用执行php页面的脚本。

Ex.: call to a cgi like this to execute the page test.php located next to it. 例如:呼叫像这样的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

This is working fine. 一切正常。

But the complete idea of Rob is to use a .htaccess to redirect calls to any php pages toward a generic cgi script. 但是Rob的完整想法是使用.htaccess将调用重定向到通用cgi脚本的任何php页面。

.htaccess .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

I have added traces in the cgi and the problem is that it's never called on my DSM 6.1. 我在cgi中添加了跟踪,问题是在我的DSM 6.1中从未调用过它。 So, it seems to me that the .htaccess is not "enabled". 因此,在我看来.htaccess未被“启用”。 Concretely, a call to the php page is downloading that file. 具体而言,对php页面的调用正在下载该文件。

Is an .htaccess assumed to be used on Synology DSM 6.1, when the DSM accesses a php page located in a non allowed path? 当DSM访问位于不允许路径中的php页面时,是否假定在Synology DSM 6.1上使用.htaccess? If it should work, what could be misconfigured on the NAS ? 如果它可以正常工作,那么在NAS上可能会配置错误?

MANY thx in adv. 副词很多 for sharing your experience on this! 分享您的经验!

Here is the demo package created by Rob to illustrate his post. 这是 Rob为演示他的帖子而创建的演示包

I finally figure out the problem. 我终于找出问题所在。 The latest versions of DSM are using nginx by default, instead of apache, as a web server. 默认情况下,最新版本的DSM使用nginx代替apache作为Web服务器。 And nginx is not using htaccess files . 而且nginx 没有使用htaccess文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM