我已经使用Apache 2.4和PHP5-FPM 5.5.9设置了Ubuntu Server 14.04.1。我已配置Apache,将proxy_fcgi与ProxyPassMatch一起使用:
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/var/www/$1
这是按预期工作的:我访问页面,内容呈现,一切看起来都超级。
现在我添加了一些内容和一个.htaccess,它应该隐藏一个子文件夹(Yii2 / web文件夹):
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ web/$1 [L]
这应该可以胜任 - 但事实并非如此。所以,我启用了调试日志记录:
[Mon Dec 08 10:49:57.414781 2014] [authz_core:debug] [pid 21794] mod_authz_core.c(802): [client 172.31.51.30:54313] AH01626: authorization result of Require all granted: granted
[Mon Dec 08 10:49:57.415581 2014] [authz_core:debug] [pid 21794] mod_authz_core.c(802): [client 172.31.51.30:54313] AH01626: authorization result of <RequireAny>: granted
[Mon Dec 08 10:49:57.415761 2014] [rewrite:trace3] [pid 21794] mod_rewrite.c(468): [client 172.31.51.30:54313] 172.31.51.30 - - [my.url/sid#7f4b93b491a0][rid#7f4b93a8c0a0/initial] [perdir /var/www/my.url/] strip per-dir prefix: /var/www/my.url/ ->
[Mon Dec 08 10:49:57.415898 2014] [rewrite:trace3] [pid 21794] mod_rewrite.c(468): [client 172.31.51.30:54313] 172.31.51.30 - - [my.url/sid#7f4b93b491a0][rid#7f4b93a8c0a0/initial] [perdir /var/www/my.url/] applying pattern '^(.*)$' to uri ''
[Mon Dec 08 10:49:57.416062 2014] [rewrite:trace4] [pid 21794] mod_rewrite.c(468): [client 172.31.51.30:54313] 172.31.51.30 - - [my.url/sid#7f4b93b491a0][rid#7f4b93a8c0a0/initial] [perdir /var/www/my.url/] RewriteCond: input='/' pattern='!^public' => matched
[Mon Dec 08 10:49:57.416170 2014] [rewrite:trace2] [pid 21794] mod_rewrite.c(468): [client 172.31.51.30:54313] 172.31.51.30 - - [my.url/sid#7f4b93b491a0][rid#7f4b93a8c0a0/initial] [perdir /var/www/my.url/] rewrite '' -> 'web/'
[Mon Dec 08 10:49:57.416309 2014] [rewrite:trace3] [pid 21794] mod_rewrite.c(468): [client 172.31.51.30:54313] 172.31.51.30 - - [my.url/sid#7f4b93b491a0][rid#7f4b93a8c0a0/initial] [perdir /var/www/my.url/] add per-dir prefix: web/ -> /var/www/my.url/web/
[Mon Dec 08 10:49:57.416430 2014] [rewrite:trace2] [pid 21794] mod_rewrite.c(468): [client 172.31.51.30:54313] 172.31.51.30 - - [my.url/sid#7f4b93b491a0][rid#7f4b93a8c0a0/initial] [perdir /var/www/my.url/] strip document_root prefix: /var/www/my.url/web/ -> /web/
[Mon Dec 08 10:49:57.416548 2014] [rewrite:trace1] [pid 21794] mod_rewrite.c(468): [client 172.31.51.30:54313] 172.31.51.30 - - [my.url/sid#7f4b93b491a0][rid#7f4b93a8c0a0/initial] [perdir /var/www/my.url/] internal redirect with /web/ [INTERNAL REDIRECT]
[Mon Dec 08 10:49:57.416730 2014] [authz_core:debug] [pid 21794] mod_authz_core.c(828): [client 172.31.51.30:54313] AH01628: authorization result: granted (no directives)
[Mon Dec 08 10:49:57.416905 2014] [proxy_fcgi:debug] [pid 21794] mod_proxy_fcgi.c(73): [client 172.31.51.30:54313] AH01060: set r->filename to proxy:fcgi://127.0.0.1:9000/var/www/my.url/index.php
[Mon Dec 08 10:49:57.417040 2014] [proxy:debug] [pid 21794] mod_proxy.c(1104): [client 172.31.51.30:54313] AH01143: Running scheme fcgi handler (attempt 0)
[Mon Dec 08 10:49:57.417125 2014] [proxy_fcgi:debug] [pid 21794] mod_proxy_fcgi.c(764): [client 172.31.51.30:54313] AH01076: url: fcgi://127.0.0.1:9000/var/www/my.url/index.php proxyname: (null) proxyport: 0
[Mon Dec 08 10:49:57.417203 2014] [proxy_fcgi:debug] [pid 21794] mod_proxy_fcgi.c(774): [client 172.31.51.30:54313] AH01078: serving URL //127.0.0.1:9000/var/www/my.url/index.php
[Mon Dec 08 10:49:57.417254 2014] [proxy:debug] [pid 21794] proxy_util.c(2020): AH00942: FCGI: has acquired connection for (*)
[Mon Dec 08 10:49:57.417300 2014] [proxy:debug] [pid 21794] proxy_util.c(2072): [client 172.31.51.30:54313] AH00944: connecting //127.0.0.1:9000/var/www/my.url/index.php to 127.0.0.1:9000
[Mon Dec 08 10:49:57.417542 2014] [proxy:debug] [pid 21794] proxy_util.c(2206): [client 172.31.51.30:54313] AH00947: connected /var/www/my.url/index.php to 127.0.0.1:9000
[Mon Dec 08 10:49:57.419240 2014] [proxy_fcgi:error] [pid 21794] [client 172.31.51.30:54313] AH01071: Got error 'Primary script unknown\n'
[Mon Dec 08 10:49:57.419438 2014] [proxy:debug] [pid 21794] proxy_util.c(2035): AH00943: FCGI: has released connection for (*)
[Mon Dec 08 10:49:57.488883 2014] [authz_core:debug] [pid 21794] mod_authz_core.c(802): [client 172.31.51.30:54313] AH01626: authorization result of Require all granted: granted
[Mon Dec 08 10:49:57.489025 2014] [authz_core:debug] [pid 21794] mod_authz_core.c(802): [client 172.31.51.30:54313] AH01626: authorization result of <RequireAny>: granted
[Mon Dec 08 10:49:57.489334 2014] [core:info] [pid 21794] [client 172.31.51.30:54313] AH00128: File does not exist: /var/www/my.url/favicon.ico
[Mon Dec 08 10:49:57.682546 2014] [proxy:debug] [pid 21831] proxy_util.c(1694): AH00925: initializing worker fcgi://127.0.0.1:9000/var/www/my.url/$1 shared
[Mon Dec 08 10:49:57.682753 2014] [proxy:debug] [pid 21831] proxy_util.c(1734): AH00927: initializing worker fcgi://127.0.0.1:9000/var/www/my.url/$1 local
[Mon Dec 08 10:49:57.682819 2014] [proxy:debug] [pid 21831] proxy_util.c(1785): AH00931: initialized single connection worker in child 21831 for (127.0.0.1)
特别是这部分看起来很有趣:
strip per-dir prefix: /var/www/my.url/ ->
applying pattern '^(.*)$' to uri ''
RewriteCond: input='/' pattern='!^public' => matched
rewrite '' -> 'web/'
add per-dir prefix: web/ -> /var/www/my.url/web/
strip document_root prefix: /var/www/my.url/web/ -> /web/
internal redirect with /web/ [INTERNAL REDIRECT]
所以,重写似乎有效,但INTERNAL REDIRECT之后发生了什么?为什么ProxyPassmatch忽略了这个重写?我错过了什么吗?
提前致谢!
编辑: VHost:
<VirtualHost *:80>
ServerName my.url
ServerAdmin me@myurl
DocumentRoot "/var/www/my.url"
LogLevel DEBUG rewrite:trace8
ErrorLog ${APACHE_LOG_DIR}/my.url.error.log
CustomLog ${APACHE_LOG_DIR}/my.url.log combined
<Directory "/var/www/my.url">
Options -Indexes
Require all granted
AllowOverride All
</Directory>
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/var/www/my.url/$1
DirectoryIndex index.php
</VirtualHost>
答案 0 :(得分:1)
您遇到的问题是您尝试以交互不确定的方式使用两个单独的Apache模块。要么执行Rewrite和反向代理,要么:
ProxyPassMatch ^/public/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/var/www/public/$1
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/var/www/web/$1
或者在重写规则中使用[proxy]
标志,以便mod_rewrite
中的执行排序规则适用:
RewriteEngine on
RewriteRule ^(?!public/).*$ web/$0
RewriteRule ^.*\.php(/.*)?$ fcgi://127.0.0.1:9000/var/www/$0 [P, END]
请注意$0
是&#34;整个匹配字符串&#34;而(?:)
是一个负面的先行断言;这消除了对RewriteCond
的需求。在其中任何一个中,规则优先权都很明确。