How to use Apache to reverse proxy to NodeJS app on LAN - apache

I have a LAN network with a server and client at addresses MYSERVER.IP and MYCLIENT.IP.
The server has a nodeJS app running on port 3000. Navigating in the browser from the client machine to MYSERVER.IP:3000/ connects to the app.
I would like to use a custom domain like www.MYTEST.APP/, without a DNS server, and have edited the hosts file on both the client and the server.
Ping to www.MYTEST.APP returns a response from MYSERVER.IP, when tested on both machines. However, http://www.MYTEST.APP/ in the browser is unreachable.
My Apache Virtual Host configuration looks like this:
<VirtualHost *:80>
ServerName MYTEST.APP
ServerAlias www.MYTEST.APP
ProxyPreserveHost On
ProxyPass / http://MYSERVER.IP:3000/
ProxyPassReverse / http://MYSERVER.IP:3000/
</VirtualHost>

Related

Https server works locally, not through internet with Apache 2.4

I'm kind of a new Apache user (version 2.4). I'm having trouble configuring the whole thing. My server has an IP address- 192.168.2.10, for example my public IP is 123.123.123.123. In my hosting provider website I did set an A record pointing at 123.123.123.123. My Apache config looks like:
Listen 443
<VirtualHost _default_:433>
# General setup for the virtual host
DocumentRoot "${SRVROOT}/htdocs"
ServerName www.example.com:443
ServerAdmin my#mail.com
ErrorLog "${SRVROOT}/logs/error.log"
TransferLog "${SRVROOT}/logs/access.log"
The problem is I receive ERR_CONNECTION_TIMED_OUT all the time. When I tried swaping www.example.com with local IP 192.168.2.5 it KIND OF worked (SSL certificate problems because they are connected to www.example.com, but I managed to see HTTP response. Where seems to be the problem?
EDIT:
I think the problem is I can't use port 443 because it's my routers default managment port. How should I configure it then? I have NAT rule on my router that does forward every :8456 request to 192.168.2.10:443.
I resolved the issue. It was "SSL 3.0" option turned off on my router.

How to redirect https request from one port to another

I have a VPS host that handles a subdomain (gate.domain.eu).
Right now I have a secondary machine in a private network connected to VPN running a gitlab instance. Using vpn,and port forwarding, i managed to bring that gitlab instance to https://gate.domain.eu:8443.
How can I configure the apache server that it will point another subdomain eg(gitlab.domain.eu) to https://gate.domain.eu:8443?
The ideea is that a user should access gitlab trough gitlab.domain.eu.
I configured DNS server for gitlab.domain.eu and configured apache virtual host as follows:
<VirtualHost *:80>
ServerAdmin me#mydomain.com
ServerName gitlab.domain.eu
ProxyPreserveHost On
# setup the proxy
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
ProxyPass / https://gate.domain.eu:8443/
ProxyPassReverse / https://gate.domain.eu:8443/
</VirtualHost>
When accessing gitlab.domain.eu I get:
"Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request."

Apache 2.4 reverse proxy

I have devserver on intranet with ubuntu, apache 2.4. There is some service running on direct ports like yourtrack on port 9000.
When I connecting directly its working properly (http://devserver:9000/).
But I want to make on this format. http://devserver/yourtrack
How could I do this?
You could use apache proxying to your application. So you declare the port 80 virtual host and the use proxy pass to proxy to the other port.
<VirtualHost *:80>
ServerName devserver
ProxyPreserveHost On
ProxyPass /yourtrack http://devserver:9000/
ProxyPassReverse /yourtrack http://devserver:9000/
</VirtualHost>
WARNING: This could have adverse effect on the application you're running depending what it does with http requests.

Proxy mechanism - forward subdomain to external server

How can I redirect one subdomain to an external server without using a proxy ? I use the mod_proxy - ProxyPass setting that works.
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName sub.domain.org
ProxyPass / http://otherDomain.org
ProxyPassReverse / http://otherDomain.org
</VirtualHost>
My current concern is that all traffic goes through domain.org. This is a virtual machine while and otherDomain is a real physical machine. I use OtherDomain because the webservice is data heavy. Would proxying the full traffic through domain.org slow down everything? How can I just forward to otherDomain.org ? Edit: Please note that domain.org is registered at a provider but otherDomain.org is just a machine with an IP address, registered nowhere.
As you are proxying all traffic to another server the simplest solution is to change the DNS record of sub.domain.com to match the DNS record of otherdomain.com.
In the Apache vHost at otherdomain.com add an ServerAlias directive for sub.domain.com. That way you get rid of the proxy stuff and all clients connect directly to the target server.

connect to alternate alternate host alias with ajp protocol

I am connecting to two tomcat application via the ajp protocol.
both of which are running in separate tomcat virtual host as ROOT.war.
On the server, I have configured the /etc/hosts file
127.0.0.1 localhost tcvh1 tcvh2
apache httpd.conf:
Listen 80
NameVirtualHost *:80
<VirtualHost *:80>
#ProxyPreserveHost On
ServerName app1.example.com
ProxyPass / ajp://tcvh1:8082/
ProxyPassReverse / ajp://tcvh1:8082/
</VirtualHost>
<VirtualHost *:80>
#ProxyPreserveHost On
ServerName app2.example.com
ProxyPass / ajp://tcvh2:8082/
ProxyPassReverse / ajp://tcvh2:8082/
</VirtualHost>
Tomcat :
I have the applications deployed as:
app1 -- $CATALINA_HOME/tcvh1/ROOT.war
app2 -- $CATALINA_HOME/tcvh2/ROOT.war
Now,
If I changed the tomcat to run on port 8080, and changed the proxy pass to connect to http://tcvh1:8080, then it works. but if I used the configuration with AJP, it does NOT work.
Why does my host alias not work with AJP? is there a way to make it work?
It doesn't work because the mod_proxy_ajp always passes the host header received by httpd to Tomcat whereas the mod_proxy_http will use the host defined in the ProxyPass unless ProxyPreserveHost is set to On.
Since - as far as httpd is concerned - your virual hosts are app1.example.com and app2.example.com, these are what get passed to your Tomcat instance. Tomcat has no record of these virtual hosts. It has tcvh1 and tcvh2. Therefore all the requests will get routed to the default virtual host (which ever one is defined on your Engine element in server.xml).
There are several ways to fix this:
Rename you Tomcat virtual hosts to match your httpd virtual hosts
Add aliases ( see http://tomcat.apache.org/tomcat-7.0-doc/config/host.html#Host_Name_Aliases) to your Tomcat virtual hosts.
Personally, I'd go with option 2. Quicker and simpler.