0

I got Apache Web Server 2.4, and a JBoss 7 exposing a web project.

Since I'm working locally I made an /etc/hosts/ domain entry like:

127.0.0.1    testmask

And put this virtual host config inside my Apache:

<VirtualHost *:80>   
    ServerName testmask/
    ServerAlias  testmask
    RewriteEngine  on 
    RewriteRule   ^/$  http://testmask/MyWebapp/  [R] 
    ProxyPass / http://testmask:8080/
    ProxyPassReverse / http://testmask:8080/
</VirtualHost> 

And this works like a charm. If I put on browser:

testmask/

It redirects to:

http://testmask/MyWebapp/

So ok so far.

Now since I would like to have the same result but leaving only:

http://testmask/

I've made a proxy on rewrite rule:

RewriteRule   ^/$  http://testmask/MyWebapp/  [P] 

But I got a 404 not found problem on css and js that are relative to context root.

This is because my browser is trying to get css and js from:

http://testmask/static/
|-  css/*
|-  js/*
|-  medias/*

while they are in:

http://testmask/MyWebapp/static/
|-  css/*
|-  js/*
|-  medias/*

(typical folder structure of build\ReactJS create-react-app).

Tried different approaches via RewriteRules or Proxypass but nothing works, probably due to my poor experience on Apache.

Consider I prefer not to touch the index.html since my projects need to live alone also, since I'm developing it via npm.

Black.Jack
  • 103
  • 1
  • 5

1 Answers1

0

I would try with mod_proxy.

First enable:

a2enmod mod_proxy
a2enmod mod_proxy_http

Then in your apache config it would look like this:

ProxyPass / http://localhost/MyWebapp
ProxyPassReverse / http://localhost/MyWebapp

So now if you connect to http://localhost/ (or in your case http://testmask/) it should be proxy to MyWebapp.

chloesoe
  • 335
  • 2
  • 17
  • Could you please take a look here too: https://serverfault.com/questions/900289/base-url-from-apache-2-4-reverse-proxy – Black.Jack Mar 06 '18 at 15:56