Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
825 views
in Technique[技术] by (71.8m points)

centos - 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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...