0

I'm running a tomcat webserver on port 8080 behind a apache2, and want to redirect some ports.

For testing, I'm trying to redirect to an invalid location, as follows:

<VirtualHost *:80>
        ProxyPreserveHost On
        RequestHeader set X-Forwarded-Proto "http"

        ProxyPass / http://127.0.0.1/test80
        ProxyPassReverse / http://127.0.0.1/test80
</VirtualHost>

<VirtualHost *:8080>
        ProxyPreserveHost On
        RequestHeader set X-Forwarded-Proto "http"

       ProxyPass / http://127.0.0.1/test8080
        ProxyPassReverse / http://127.0.0.1/test8080
</VirtualHost>

Result: The :80 redirect works as expected. BUT accessing :8080 shows the tomcat manager starting page, instead of the redirect. Why?

Somehow it seems as if the apache2 could not take control of that port?

membersound
  • 275
  • 1
  • 5
  • 13

1 Answers1

1

I guess there is no Listen 8080 option in your apache config files. Just adding the port to a VirtualHost is not enough.

check one of these files (based on your distribution) for Listen options and add one for port 8080:

# /etc/apache2/ports.conf     [On Debian/Ubuntu]
# /etc/httpd/conf/httpd.conf  [On RHEL/CentOS]

more info here: https://www.tecmint.com/change-apache-port-in-linux/

But as mentioned in the comments, you cannot have two services listening on the same port. You have to change the tomcat listening port for this to work.

ttsakpc
  • 136
  • 5
  • Good idea, indeed `ports.conf` only shows 80 + 443. So I'd have to add 8080 explicit here? – membersound May 18 '22 at 12:40
  • Yes. But then apache will not start because port 8080 is used also for tomcat :) – ttsakpc May 18 '22 at 12:41
  • I can confirm this. Adding `Listen 8080` results in startup failure. So that's the solution. I'd then have to start tomcat on a different port (eg 8081), and could then listen to 8080 in apache. – membersound May 18 '22 at 12:45