Apache ProxyPass忽略静态文件

Apache前台服务器连接到Jetty应用程序服务器时遇到问题。

我认为这个ProxyPass ! 在一个位置块应该不会传递到应用程序服务器的处理,但由于某种原因,这不是在我的情况发生,Jetty显示缺less静态404(JS,CSS等)

这是我的Apache(v 2.4,BTW)虚拟主机块:

 DocumentRoot /path/to/foo ServerName foo.com ServerAdmin [email protected] RewriteEngine On <Directory /path/to/foo> AllowOverride None Require all granted </Directory> ProxyRequests Off ProxyVia Off ProxyPreserveHost On <Proxy *> AddDefaultCharset off Order deny,allow Allow from all </Proxy> # don't pass through requests for statics (image,js,css, etc.) <Location /static/> ProxyPass ! </Location> <Location /> ProxyPass http://localhost:8081/ ProxyPassReverse http://localhost:8081/ SetEnv proxy-sendchunks 1 </Location> 

您需要使用ProxyPass! 参数与path,而不是在<Location>块中,例如:

 ProxyPass /static ! ProxyPass / http://localhost:8081/ ProxyPassReverse / http://localhost:8081/ 

我相信这些规则是按照它们在configuration中出现的顺序处理的,所以一定要先指定排除规则。

Location块内部工作的方法是颠倒顺序,即最具体的Location声明最后一个

 DocumentRoot /path/to/foo ServerName foo.com ServerAdmin [email protected] RewriteEngine On <Directory /path/to/foo> AllowOverride None Require all granted </Directory> ProxyRequests Off ProxyVia Off ProxyPreserveHost On <Proxy *> AddDefaultCharset off Order deny,allow Allow from all </Proxy> <Location /> ProxyPass http://localhost:8081/ ProxyPassReverse http://localhost:8081/ SetEnv proxy-sendchunks 1 </Location> # don't pass through requests for statics (image,js,css, etc.) <Location /static/> ProxyPass ! </Location> 

这工作。 有关更多详细信息,请参见https://httpd.apache.org/docs/2.4/mod/mod_proxy.html#proxypass – 它包含一个与上面完全一样的示例。