PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, June 24, 2022

[FIXED] How to server static files + proxy context

 June 24, 2022     apache, httpd.conf, mod-proxy, mod-rewrite, reverse-proxy     No comments   

Issue

I am wondering how to configure my httpd server to serves the following pages:

My need is to serve static content located in my /var/www/static when url is /context/static and to proxy the remaining to a tomcat server

In this order:

/context/static/* --> files served by httpd
/context/*        --> resources served by tomcat

I have tried to rewrite /context/static/* to a folder pointing to my /var/www/static and added the ProxyPath directive for the remaining but I can't get it working.

What are the best practices and how to achieve that ?

Thanks in advance


Solution

Well, in fact it is quiet easy...

Having such folders configured:

/var/www/static/
               |-  css/*
               |-  js/*
                \  medias/*

The following httpd configuration will redirect static/* to the /var/www and the rest will be proxied

# first rewrite for statics
RewriteEngine On
RewriteRule ^/context/static/(.+)$ /static/$1

# then proxy remaining...
ProxyPass               /context  http://127.0.0.1:8080/context
ProxyPassReverse        /context  http://127.0.0.1:8080/context


Answered By - poussma
Answer Checked By - David Goodson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing