I'm running a very old bitnami stack (Version 8.5.16-0), but I'm not able to update it now.
I need to configure it to proxy to another service running in another port by using the ServerName
.
I tried this, but it not works:
I added to /opt/bitnami/apache2/conf/bitnami/bitnami-apps-vhosts.conf
:
<VirtualHost *:80>
ServerName sub.mycompany.com
ProxyPreserveHost On
ProxyPass / http://localhost:3001/
ProxyPassReverse / http://localhost:3001/
</VirtualHost>
So, when I access my http://mycompany.com
I need it to continue to access the default AJP proxy configuration to the tomcat. But, when I access http://sub.mycompany.com
I need to proxy to that custom service running on port 3001.
What am I doing wrong?
Hi Bitnami Engineer here,
Adding that custom VirtualHost in the /opt/bitnami/apache2/conf/bitnami/bitnami-apps-vhosts.conf
is the correct way to do this. I just launched the same solution you are using and added this to that file
<VirtualHost *:80>
ServerName mydomain
RewriteEngine On
RewriteRule ^/(.*) https://www.google.com/$1 [R,L]
</VirtualHost>
I do not have a service running in the port 3001 but I configured Apache to redirect the connections to google.com. After restarting Apache
sudo /opt/bitnami/ctlscript.sh restart apache
I verified that the configuration is correct
bitnami@ip-172-31-57-221:/opt/bitnami$ curl -LI 35.168.7.34
HTTP/1.1 200 200
Date: Thu, 20 Aug 2020 08:02:44 GMT
Server: Apache
X-Frame-Options: SAMEORIGIN
Accept-Ranges: bytes
ETag: W/"3660-1499251067000"
Last-Modified: Wed, 05 Jul 2017 10:37:47 GMT
Content-Type: text/html
Content-Length: 3660
bitnami@ip-172-31-57-221:/opt/bitnami$ curl -LI 35.168.7.34.nip.io
HTTP/1.1 302 Found
Date: Thu, 20 Aug 2020 08:02:47 GMT
Server: Apache
X-Frame-Options: SAMEORIGIN
Location: https://www.google.com/
Content-Type: text/html; charset=iso-8859-1
HTTP/1.1 200 OK
Content-Type: text/html; charset=ISO-8859-1
P3P: CP="This is not a P3P policy! See g.co/p3phelp for more info."
Date: Thu, 20 Aug 2020 08:02:47 GMT
Server: gws
X-XSS-Protection: 0
X-Frame-Options: SAMEORIGIN
Transfer-Encoding: chunked
Expires: Thu, 20 Aug 2020 08:02:47 GMT
Cache-Control: private
Set-Cookie: 1P_JAR=2020-08-20-08; expires=Sat, 19-Sep-2020 08:02:47 GMT; path=/; domain=.google.com; Secure
Set-Cookie: NID=204=qoK5Dqh-YCXNgqKmQQVLwHmxmLc7Pa7xoWcPc5iNnb_AqNTdDffYK7dpjoLFalVKEaS-vsKRcNUeJlLkO3GN-jNI4BUGzT0V2--66luMecjNoUWXcriPM8UhX2KtEqFd3Qw2Iu9NE10qeAnvhbDHw34sLDnheaYokmEeUALrSpg; expires=Fri, 19-Feb-2021 08:02:47 GMT; path=/; domain=.google.com; HttpOnly
Alt-Svc: h3-29=":443"; ma=2592000,h3-27=":443"; ma=2592000,h3-T050=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"
As you can see, the request that used the custom VirtualHost got redirected to www.google.com.
In order to debug your problem, I'd follow these steps:
curl -LI localhost:3001
Ensure the requests to sub.mycompany.com
is using your custom virtual host. You will need to ensure that sub.mycompany.com is not set as the default domain in the /opt/bitnami/apache2/conf/httpd.conf
file and that you didn't include that domain in the /opt/bitnami/apache2/conf/bitnami/bitnami.conf
file either. You can try using the code I posted above to test the virtual host.
Remember to restart Apache after applying any change to the configuration
I hope this information helps