Apache 2.4:如果本地文件不存在,则使用代理重定向

时间:2019-04-22 08:54:45

标签: mod-rewrite proxy apache2 mod-proxy

我想检查文件是否在本地存在,如果不存在,我想通过代理将请求传递给应用,该代理会生成该文件。

那是我已经尝试过的:

    # do the rights processing for non-docroot-paths
    <Directory /webapps/mapproxy/cache_data/demo>
        Options +FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
        Require all granted
    </Directory>

    <LocationMatch "^/tiles/(.*)$">
        # check if exists
        RewriteCond /webapps/mapproxy/cache_data/demo/$1 !-f

        # deliver locally if file exists
        RewriteRule (.*) - [L]

        # if file doesn't exist, send request to backend 
        RewriteRule "^/(.*)" "http://localhost:8000/wmts/demo/webmercator/$1" [P]
        ProxyPassReverse http://localhost:8000/wmts/demo/webmercator/$1
    </LocationMatch>

一些例子:

1. request to http://$URL/tiles/12/4255/5469.png
2. internal "/webapps/mapproxy/mapproxy/cache_data/demo/12/4255/5469.png" exists
3. file should get delivered from internal storage

1. request to http://$URL/tiles/12/4255/5469.png
2. internal "/webapps/mapproxy/mapproxy/cache_data/demo/12/4255/5469.png" does NOT exist
3. proxy-request to "http://localhost:8000/wmts/demo/webmercator/12/4255/5469.png"
3.1 it permanently generates "/webapps/mapproxy/mapproxy/cache_data/demo/12/4255/5469.png"
3.2 it delivers "/webapps/mapproxy/mapproxy/cache_data/demo/12/4255/5469.png"

也许我还需要使用 Alias

0 个答案:

没有答案