Redireting Https requests on Apache for Wildfly
Asked Answered
H

2

0

I am using Apache Virtual Hosts to run multiple websites. I am using apache in Front and this apache is redirecting the url request to the wildfly Server.

My Apache Configuration is working fine for http request using below code

<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName mysitedemo.com
    ServerAlias www.mysitedemo.com
    <Proxy *>
            Order deny,allow
            Allow from all
    </Proxy>
    ProxyRequests Off
    ProxyPreserveHost On
    ProxyPass / http://localhost:8080/
    ProxyPassReverse / http://localhost:8080/
    ErrorLog "logs/mysitedemo-error_log"
    CustomLog "logs/mysitedemo-access_log" common
</VirtualHost>

Now I also want to handle Https Request for that i have added below code in vhosts file

<VirtualHost *:443>
    ServerAdmin [email protected]
    ServerName mysitedemo.com
    ServerAlias www.mysitedemo.com
    <Proxy *>
            Order deny,allow
            Allow from all
    </Proxy>
    ProxyRequests Off
    ProxyPreserveHost On
    ProxyPass / https://localhost:8443/
    ProxyPassReverse / https://localhost:8443/
    ErrorLog "logs/mysitedemo-error_log"
    CustomLog "logs/mysitedemo-access_log" common
</VirtualHost>

But it is not working properly giving me, the following error

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at [email protected] to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.

I have setup the SSL on Wildfly server. Do I need to buy separate SSL for Apache as well or can I use the same SSL on Apache? If yes, then please explain how I can do that?

Herewith answered 24/8, 2017 at 6:45 Comment(1)
I have fixed the internal server error, It was due to my SSLProxyEngine was not enabled. Now Please help me to know Do i need to buy seperate SSL for apache, as SSL is already running on Wildfly port 8443 ?Herewith
V
2

Redireting Https requests on Apache for Wildfly

If one augments the information in your question with the additional information in the comments one can see that you don't actually redirect the client as you claim in various places in your question. In case of a redirect the server will tell the client to ask a different server. What you do instead here is forwarding where your Apache works as reverse proxy and forwards the request from the client to the Wildfly server and sends the response from the Wildfly back to the client.

Since in this case the client is only directly interacting with the Apache server this Apache server will do the TLS handshake if HTTPS is used by the client. This means that the Apache must have the appropriate certificates configured and SSL enabled. The Apache will then terminate the original HTTPS connection from the client. Since you have configured ProxyPass to a HTTPS url Apache will then do another HTTPS connection to the proxied Wildfly server. And, from the perspective of the client it does not matter if the Wildfly server is HTTPS enabled or not - all what matters is how to access the Apache server.

Viol answered 24/8, 2017 at 8:55 Comment(4)
Thank you so much for your help sir.Herewith
One last query sir. I have SSL certificate (demo.keystore) that I have used on wildfly server. Can i use the same certificate on apache ? or will i have to buy new one for apache. If i can use same certificate, then please tell how can i use the same ??Herewith
@Tarun:There are no technical restrictions on reusing the same certificate on multiple hosts but the name used in the URL must of course match the subject of the certificate. But you should check if your issuer CA has added legal usage restrictions. Apart from that there is nothing special to do when configuring multiple systems to use the same certificate compared to using different certificates.Viol
Thanks sir for the great help.Herewith
V
1

To redirect from https://siteA to https://siteB you need to have first a certificate for siteA (and siteB of course too) and then properly configure it. In your case you have neither configured a certificate nor have you configured https at all at port 443. Instead you have just configured port 443 as yet another HTTP (but not HTTPS) server which of course gives errors when trying to access it with HTTPS.

Viol answered 24/8, 2017 at 7:7 Comment(3)
Thank you sir for your reply. My internal server error issue is resolved. It was due to SSLProxyEngine, because i have not enabled SSLProxyEngine. After enabling it. My Internal Server error has gone.Herewith
Sir Actually My Problem is not navigating from one website to another website. Actually it is that when apache recieves the HTTPS request it should be redirected to Wildfly Port 8443 with secure connection. Now we have https running on wildfly. Do i have to add seperately ssl files for apache ??Herewith
@Tarun: in this case you are not redirecting as you claim but forwarding. See my other response then.Viol

© 2022 - 2024 — McMap. All rights reserved.