Search code examples
apachecentosvirtualhosthttpd.conf

Apache to server both static file and webapp


I have apache running on below reverse proxy config to serve java webapp content

<VirtualHost *:80>
SSLProxyEngine on
ProxyPreserveHost On
ProxyRequests Off

ServerName www.example.com
ServerAlias example.com

<Location />
        Order deny,allow
        Allow from all
        SetOutputFilter INFLATE;DEFLATE

        ProxyPass  http://localhost:7070/
        ProxyPassReverse  http://localhost:7070/
        AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript
</Location>

</VirtualHost>

Now i want to add static file folder and should be served under the same same domain name but under "/auth" path https://example.com/auth

so i added below config just below the above

<Location /auth>
      Require all granted
      Allow from all
</Location>

DocumentRoot /var/www/html/auth/
<Directory /var/www/html/auth>
        Require all granted
        DirectoryIndex index.html
</Directory>

But when i try "https://example.com/auth" it still goes to java webapp and gives me 404 When i curl localhost i can see webpage content

curl http://localhost

how to access static content on /var/www/html/auth/ using https://example.com/auth URL


Solution

  • I'm not sure while you're using "Location" to match the entire document root since you're passing everything to the proxypass: IMHO you can completely remove those 2 lines ("" and "/").

    To exclude path from proxypass you can use the "!" (documentation: https://httpd.apache.org/docs/current/mod/mod_proxy.html#proxypass). Below an example that should work if you don't want to change your configuration:

    <Location "/main-dir/sub-dir/">
        ProxyPass "http://backend.example.com/"
    </Location>
    <Location "/main-dir/sub-dir/static-content">
        ProxyPass "!"
    </Location>