0

I want to set couple of Location tags in my Apache config. For instance: /image, /file, /audio and to pass it to localhost:port/path. Right now I'm using this for /image:

 <Location /image>
        RewriteEngine  on
        Options +MultiViews +FollowSymLinks
        AllowOverride All
        ProxyPreserveHost On
        ProxyPass "http://localhost:PORT/image"
        ProxyPassReverse "http://localhost:PORT/image"
    </Location>

Do I have to write this piece of code for every param? Or there is any shortcut for it?

Thanks!

1 Answers1

0
<Location /image>
   RewriteEngine  on
   Options +MultiViews +FollowSymLinks
   AllowOverride All
   ProxyPreserveHost On
   ProxyPass "http://localhost:PORT/image"
   ProxyPassReverse "http://localhost:PORT/image"
</Location>

Do I have to write this piece of code for every param?

No. The RewriteEngine directive doesn't do anything there and neither the Options nor the AllowOverride directives make any sense when you don't map to resources on the local file system. Those options are controlled and need to be set by the "remote" webserver that you are forwarding the requests to with the ProxyPass directive.

Since those directives are useless, then you don't need the Location bracket either to set them and can use the inline ProxyPass syntax that is recommended anyway.

That reduces your syntax to only the necessary lines:

ProxyPreserveHost On

ProxyPass "/image" "http://localhost:PORT/image"
ProxyPassReverse "/image" "http://localhost:PORT/image"

ProxyPass "/file" "http://localhost:PORT/file"
ProxyPassReverse "/file" "http://localhost:PORT/file"

Apache httpd does offer the Include directive to maintain a single configuration snippet with settings that you want to include verbatim in different places, VirtualHost, Location, Directory blocks without copying the same lines time after time.

Bob
  • 5,805
  • 7
  • 25