Score:0

How to redirect port 8080 with apache?

eg flag

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?

in flag
Only one process can listen on a port on an interface. If tomcat is listening on that port, apache can't.
eg flag
Okay but why does apache then not complain, even not on a restart?
Score:1
cn flag

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.

eg flag
Good idea, indeed `ports.conf` only shows 80 + 443. So I'd have to add 8080 explicit here?
ttsakpc avatar
cn flag
Yes. But then apache will not start because port 8080 is used also for tomcat :)
eg flag
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.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.