Bobcares

How we redirect port 80 to 8080 in Apache and fix related errors

by | Sep 6, 2019

Web server listens on port 80 by default.

But for running applications like Tomcat or JBoss on the same server, we need to redirect port 80 to 8080 in Apache configuration.

However, it may not always work due to improper Apache settings and ends up in website errors.

At Bobcares, we often get requests from our customers to fix redirect port 80 to 8080 apache errors as part of our Server Management Services.

Today, this write-up describes how our Support Engineers fix Apache port redirection errors.

 

How to redirect port 80 to 8080 in Apache

It’s pretty easy to route Apache to another port. Let’s see how our Support Engineers route port 80 to 8080.

1. Initially, we login into the server as a root user.

2. Then, we create the file /etc/apache2/other/port8080-redirect.conf.

nano -w /etc/apache2/other/port8080-redirect.conf

3. After that, we add the following code into the file and save it.

<VirtualHost _default_:80>
DocumentRoot /home/user/website_folder
RewriteEngine On
# Redirect all requests to the local Apache server to port 8080
RewriteRule ^.*$ http://%{HTTP_HOST}:8080%{REQUEST_URI}
</VirtualHost>

Document root may vary with server settings.

4. At last, we restart the Apache service.

apachectl restart

In addition, this port redirection set up with Apache module mod_proxy. For this, we should enable mod_proxy on the server.

 

How we fixed the common errors

At Bobcares, where we have more than a decade of expertise in managing servers, we see many customers face problems while redirecting port 80 to 8080 in Apache.

Now let’s see how our Support Engineers fixed the top errors.

 

1. Incorrect proxy settings

Recently, one of our customers had a problem while redirecting port 80 to 8080 in Apache.  He got an error when restarting the apache service after updating the rule in the apache configuration file, The error said,

Syntax error on line 207 of /etc/apache2/apache2.conf: Syntax error on line 1 of /etc/apache2/httpd.conf: Cannot load /etc/apache2/modules/mod_proxy.so into server: /etc/apache2/modules/mod_proxy.so: cannot open shared object file: No such file or directory
Action '-k graceful' failed.

It was clearly a syntax error in specifying the proxy module. So, we correctly added a line to load proxy_module in httpd.conf.

LoadModule proxy_module modules/mod_proxy.so

And, we ensured that the file exists with correct permissions.

Also, in the path set in DocumentRoot, we edited the links for each application in Tomcat’s web apps directory. Otherwise, the HTTP server will not be able to load resource files, like CSS and JS.

That fixed the problem and the website started working fine.

 

2. Wrong firewall

A common error when using custom Apache ports relates to the server firewall. Often server owners fail to open port 8080 in the server. This can cause the website to fail.

Therefore our Dedicated Engineers open port using the firewall application that the server uses. For instance, in iptables, we use:

iptables -I INPUT -p tcp --dport 8080 -j ACCEPT 

Or when the server has Plesk control panel, we open port from admin panel at:

 

3. Missing Module

Similarly, customers often complaints that the port forwarding is not working on their server. They may consider that it may happen due to improper port settings in the server. However, web apps like Tomcat need a mod_proxy module that easily routing a Tomcat web app to an Apache frontend.

Therefore, our Support Engineers ensure that the mod_proxy and mod_proxy_http enabled on the server. If not we’ll enable it for the proper working of port forwarding.

[Need assistance in port forwarding and to fix related errors? We’ll help you.]

 

Conclusion

In short, when redirecting port 80 to 8080 in Apache, error may happen due to the improper settings in the configuration file. Today, we saw how our Support Engineers fix redirect port 80 to 8080 apache related errors.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.