[英]mod_rewrite not working with reverse proxy in vhost
All I am trying to do is: 我要做的就是:
The trick is that those files are on a remote (public) server which I'm reverse proxying to. 诀窍是这些文件位于我反向代理到的远程(公共)服务器上。 I am doing this so I can workaround the same-origin issue with our javascript, and to speed up delivery in general.
我这样做是为了解决我们的JavaScript的同源问题,并总体上加快投放速度。 The .gz files already exist.
.gz文件已经存在。 No matter what I do, I cannot request the .js file and have the .gz file returned.
无论我做什么,我都无法请求.js文件并返回.gz文件。 I have tried this with numerous different RewriteConds to no avail.
我尝试了许多不同的RewriteConds都没有用。 I have also tried it with RequestHeader unset Accept-Encoding enabled, and commented out.
我还尝试了启用RequestHeader未设置Accept-Encoding并将其注释掉的尝试。 Google PageSpeed keeps telling me that it is not receiving the compressed versions, and when I request using curl and manually setting the "Accept-Encoding: gzip, deflate" header, I continue to receive the non-compressed versions.
Google PageSpeed一直告诉我它没有收到压缩版本,当我请求使用curl并手动设置“ Accept-Encoding:gzip,deflate”标头时,我继续收到未压缩的版本。 I cannot put the rewrites in the .htaccess file because the reverse proxy is processed before the .htaccess, and I need the rewrite to already be in effect when the reverse proxy happens.
我无法将重写内容放在.htaccess文件中,因为在.htaccess文件之前已处理了反向代理,因此我需要在发生反向代理时重写已经生效。 I'm at a total loss.
我完全不知所措。
Here is my non-production setup (I know it needs securing): 这是我的非生产设置(我知道它需要固定):
<VirtualHost *:80>
ServerName ww.test.com
DocumentRoot "/htdocs/public"
Options +MultiViews
AddEncoding x-gzip .gz
AddEncoding gzip .gz
RewriteEngine on
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteRule ^\.js$ $1\.js\.gz [L]
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteRule ^\.css$ $1\.css\.gz [L]
<FilesMatch .*\.css\.gz>
ForceType text/css
Header append Content-Encoding gzip
</FilesMatch>
<FilesMatch .*\.js\.gz>
ForceType text/javascript
Header append Content-Encoding gzip
</FilesMatch>
ProxyRequests off
ProxyPass /static/ http://www.ourCDN.com/ourAccount/environmentName/
<Location /static/>
ProxyPassReverse /
#RequestHeader unset Accept-Encoding
</Location>
<Directory />
Options FollowSymLinks
AllowOverride All
Order deny,allow
</Directory>
</VirtualHost>
FilesMatch
rules apply only to files on disk - a proxied request isn't a file on disk and therefore won't be captured by a FilesMatch
rule. FilesMatch
规则仅适用于磁盘上的文件-代理请求不是磁盘上的文件,因此, FilesMatch
规则不会捕获该请求。
You probably want 你可能想要
<LocationMatch "^/static/.*\.css\.gz$">
ProxyPassReverse /
....
</LocationMatch>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.