简体   繁体   中英

Apache ProxyPass not working for custom app

i have the following situation: i need to call the following url http://myapp.mydomain.com

and the url should reply as following http://myapp.mydomain.com/index.jsp

On my apache 2.4 i tryied different setup but none seems to work,

First attempt

<VirtualHost *:80>
    ProxyPreserveHost On
    ProxyPass /myapp http://127.0.0.1:8080/myapp
    ProxyPassReverse /myapp http://127.0.0.1:8080/myapp
</VirtualHost>

Second attempt

<VirtualHost *:80>
    ProxyPreserveHost On
    ProxyPass /myapp/ http://127.0.0.1:8080/myapp/
    ProxyPassReverse /myapp/ http://127.0.0.1:8080/myapp/
</VirtualHost>

Third attempt

    <Location "/myapp/">
        ProxyPreserveHost On
        ProxyPass / http://127.0.0.1:8080/myapp/
        ProxyPassReverse / http://127.0.0.1:8080/myapp/
   </Location>

Fourth attempt

<Location "/myapp/">
    ProxyPreserveHost On
    ProxyPass /myapp/ http://127.0.0.1:8080/myapp/
    ProxyPassReverse /myapp/ http://127.0.0.1:8080/myapp/

None of the configuration seem to work, the url https://myapp.mydomain.com brings up the welcome page of the tomcat. And what ever configuration i apply to apache, the only way to make it work is to manually add on the link the mountpoint of proxy, as following

http://myapp:mydomain.com/myapp/index.jsp

Any suggestion on how can i make this work? Thanks in advance.

I don't have enough cred to comment and ask for clarification, so I'll edit my answer based on your feedback.

When using the VirtualHost, which I believe is your best option, you need a ServerName directive included as well. (Perhaps you omitted it here on purpose for some reason, but I'm showing it in the example below).

Also, I believe your route parameters for ProxyPass and ProxyPassReverse need to be in quotes unlike many other items in a VirtualHost. Make particular note of the trailing slash after myapp in the destination (second parameter). Since your desired URL would have index at the root path of your myapp.mydomain.com subdomain, make sure you're indicating that (as the first parameter, / ). That should cause the URL https://myapp.mydomain.com to point to http://127.0.0.1:8080/myapp/ as you intend. (In your Example 2, you made your first parameter /myapp/ and, thus, you had to add this to your URL to access it, as you noted -- minus where you swapped a colon for a dot.)

(Disclaimer: I don't know much about Tomcat, but I am operating on the presumption that index.jsp should be treated like most other "index" files in that they'll be sought out and used if they exist and can, therefore, be omitted from the URL requested by the client).

I've also added the ProxyRequests below as I do not know if the default is "Off" or not, but unless you're using a forward proxy (versus the apparent reverse you want here) I think it's at least a potential security issue not to do so.

Minus any other directives you've not shown here, it seems this should do the trick:

<VirtualHost *:80>
  ServerName myapp.mydomain.com
  ProxyRequests off
  ProxyPreserveHost On
  ProxyPass "/" "http://127.0.0.1:8080/myapp/"
  ProxyPassReverse "/" "http://127.0.0.1:8080/myapp/"
</VirtualHost>

Original reply was from mobile; I've cleaned it up and added an example and clearer explanation from desktop.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM