Forwarding subdomain to a port of localhost using WHM and apache2 - apache

In brief, I can access my site using example.com:3000 but I want to access it using sub.example.com.
I am using WHM to manage my server using the example.com domain. I have added a DNS Zone using the WHM control panel for sub.example.com. It works fine and redirects to sub.example.com/cgi-sys/defaultwebpage.cgi.
I also tried to make a reverse proxy using VirtualHost by adding the following lines to the /etc/apache2/conf/httpd.conf file as mentioned in here:
<VirtualHost *:80>
ServerName sub.example.com
ProxyPreserveHost on
ProxyPass / http://localhost:3000/
</VirtualHost>
Then I restarted the Apache server using sudo systemctl restart httpd. However the subdomain still redirects to the sub.example.com/cgi-sys/defaultwebpage.cgi path rather than forwarding to the port:3000. Could you please help me resolve this problem?
It is worth mentioning that the server is using WHM and CPanel (version 84.0.21) on CentOS (version 7.7) as well as Apache (version 2.4.41) and the port:3000 is connected to a docker image (gitea) via docker-compose.

I had the same issue with the same setup and was able to solve it by using this configuration:
<VirtualHost sub.example.com:80>
ServerName sub.example.com
ServerAlias sub.example.com
ProxyRequests Off
ProxyPreserveHost On
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
</VirtualHost>
Adding it to Apache's include directive in WHM:
https://docs.cpanel.net/whm/service-configuration/include-editor/
For SSL port 443 you have to use the IP instead of domain:
<VirtualHost 1.1.1.1:443>

Related

Apache ProxyPass HTTP does not work with SSL

I was trying to add cloudflare SSL certification to the website I host locally, and force HTTPS for all users.
Connecting to IP:80 works fine (from inside my network). IP:443 fails as it expects a SSL certificate. Accessing domainname.com tells me the site is secure, so the SSL certificate works. But whenever I access it this way, the proxy website doesn't, displaying the 'Apache2 Default Page'. Same with connecting to IP:80 outside the network, it fails to proxy pass.
This is the config file I have setup, and by running apachectl -S I checked that no other rules exist.
<VirtualHost *:80>
ServerName name.com:80
ProxyPreserveHost On
ProxyPass / http://localhost:7000/
ProxyPassReverse / http://localhost:7000/
</VirtualHost>
<VirtualHost *:443>
ServerName name.com:443
SSLEngine on
SSLCertificateFile /etc/cloudflare/name.com.pem
SSLCertificateKeyFile /etc/cloudflare/name.com.key
ProxyPreserveHost On
ProxyPass / http://localhost:7000/
ProxyPassReverse / http://localhost:7000/
</VirtualHost>
Is this because I am trying to load an http website, even though it is local? And if this is true, how else can I solve this problem? I feel so close, thanks for the help.
I solved it, by switching to the default-ssl config file provided with Apache2, and removing my version the issue resolved itself. Not sure why it worked the second time I tried it but oh well.

Gogs.io running on subdomain with port

I'm trying to run Gogs.io on an apache webserver along with a standard website, and I'm trying to have Gogs.io used on a subdomain rather than using my standard domain with a port.
Gogs.io runs on port 3000, and I want the url to be
http://gogs.example.net/
Rather than
http://example.net:3000/
Both my public IP with port and example.net:3000 work, but when trying to use gogs.example.net, I always get an AT&T DNS Error Assist page. I'm not sure what I'm doing wrong, as I had it working earlier until I tried to change the name of the subdomain in my apache config, but I changed it back when I started having issues, to no luck.
Here is my Apache config for the page:
<VirtualHost *:80>
ServerName gogs.example.net
ProxyPreserveHost On
ProxyPass / http://example.net:3000/
ProxyPassReverse / http://example.net:3000/
</VirtualHost>
This may be impossible, but any help would be greatly appreciated!
Fixed the issue by adding an A record to my domain
A Record: git -> 111.222.333.444
As well as modified the VirtualHost settings to include the subdomain in the ProxyPass and ProxyPassReverse
<VirtualHost *:80>
ServerName gogs.example.net
ProxyPreserveHost On
ProxyPass / http://git.example.net:3000/
ProxyPassReverse / http://git.example.net:3000/
</VirtualHost>

Using Joomla on Apache behind Apache Reverse Proxy

I have a Joomla Installation on Apache2 (Port 83) running on Ubuntu 16.04 Server.
When I connect to the page from the local network like 192.168.178.14:83 it appears and everything is fine. To access my page from the Internet there is another Server running Apache2, that acts as a Proxy Server. All traffic going trough Port 80 and 443 come to this machine, using the ServerName it decide to which machine the traffic have to be forwarded. That's working fine for about 10 domains and machines.
But when I connect to my Joomla Domain I get a HTML Site without any formatting, graphics and templates. When I forward a Port directly to this machine everything works fine again, using this port to connect.
network topologie
My VirtualHost config on Ubuntu1:
<VirtualHost *:80>
ServerName ksg-events.de
Redirect permanent / https://ksg-events.de/
</VirtualHost>
<VirtualHost *:443>
ServerName ksg-events.de
ProxyPreserveHost On
ProxyRequests Off
ProxyVia Off
ProxyPass / http://192.168.178.14:83/
ProxyPassReverse / http://192.168.178.14:83/
SSLCertificateFile /etc/letsencrypt/live/ksg-events.de/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/ksg-events.de/privkey.pem
</VirtualHost>
Virtual Host config on Ubuntu2:
<VirtualHost *:83>
DocumentRoot /var/www/ksg-events.de/joomla
</VirtualHost>
Thanks for your help!
I find a solution to my problem:
Run Joomla behind Apache reverse proxy (http):
Add ProxyVia full to proxy's VirtualHost config
Using https:
Enable mod_headers on proxy server
Add RequestHeader set X-Forwarded-Proto "https" to proxy's VirtualHost
I hope that can help someone who run into the same problems.

Two applications on same port 80 with apache proxy?

I have two applications on one server: Redmine running under Apache and application running under WildFly. Now, Redmine runs on port 80 and the other application runs on port 8080.
Is it possible to run them both on port 80 using Apache reverse proxy ? This server would have assigned two domain names: app.domain.com for application under WildFly and redmine.domain.com for redmine application under Apache.
Is it possible to achieve following behavior ?
I access to redmine.domain.com, I am redirected to /var/www/redmine DocumentRoot folder.
And when I access to client.domain.com, I am redirected to http://localhost:8080.
Thank you
This is easy to do with apache. You can't bind two applications to one port but you can have apache route them.
What you want to do is run Apache on port 80, wildfly on 8080, redmine on 8081.
Within apache the configuration would look like this:
<VirtualHost app.domain.com:80>
ProxyPass / http://127.0.0.1:8080/ retry=0
ProxyPassReverse / http://127.0.0.1:8080/
</VirtualHost>
<VirtualHost redmine.domain.com:80>
ProxyPass / http://127.0.0.1:8081/ retry=0
ProxyPassReverse / http://127.0.0.1:8081/
</VirtualHost>

OpenERP 7 Apache redirect not working

Here is the situcation.
I installed OpenERP instance on Amazon EC2 Ubuntu 12.04.
Use serverip:8069 or domain-one.com:8069 to access website is no problem. Then i set up apache reverse proxy to use domain-two.com for openERP, i can't access the website. here is proxy setting:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName domain-two.com
RewriteEngine on
RewriteRule ^/(.*) http://localhost:8069/$1 [P]
ProxyPassReverse / http://localhost:8069/
</VirtualHost>
But when i add this to my computer /etc/hosts file:
serverip domain-two.com
and then visit the domain-two.com, successfully visit the OpenERP instance.
domain-two nameserver setting in Route53 is correct. no problem
Where i'm doing it wrong? please help.
Many Thanks!
First check whether your DNS setting is working fine or not using the dig command from linux os.
dig domain-two.com
And then use this configurations and try again.
NameVirtualHost *:80
<VirtualHost *:80>
ServerName domain-two.com
ProxyPass / http://localhost:8069/
ProxyPassReverse / http://localhost:8069/
</VirtualHost>
Please dont forget to restart the Apache server. Remember this configuration will not work for SSL based Proxy.