Apache 2.4 reverse proxy - apache

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.

Related

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

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>

How do I setup an Apache ProxyPass / Reverse Proxy while listening on an alternate port?

I had Apache configuration which was using a ProxyPass/ProxyPassReverse with the following example syntax:
ProxyPass /myprog http://localhost:8080/myprog
ProxyPassReverse /myprog http://localhost:8080/myprog
Then, I moved Apache from port 80, to 8880, and put another web server on port 80. I can access some things correctly now on port 8880 - those files which are hosted directly on Apache. But my proxy pass (to Tomcat) now fails when I try to access it at: http://some.domain:8880/myprog.
How do I correct the ProxyPass/Reseverse to account for the port change? (I assumed, perhaps natively, the port spec was implicit...).
You need to put your configuration on a VirtualHost tag.
<VirtualHost *:8880>
ProxyPreserveHost On
ProxyRequests Off
ProxyPass /myprog http://localhost:8080/myprog
ProxyPassReverse /myprog http://localhost:8080/myprog
</VirtualHost>

Apache HTTP Server reverse proxying from port 80 to port *

I have a Suse Linux server with a web application listening on Port 51058.
I want now to use Apache HTTP Server to forward the user from port 80 to this port so that when the user types the url in the Browser the user sees the application on port 51058.
I do not want to use redirection because i must open then also the port 51058. Is it possible to do something like this with Apache HTTP Server?
If yes how can I do this?
You will need to setup a reverse proxy with Apache using the mod_proxy module.
You may use something like this a Virtual Host for port 80:
<VirtualHost *:80>
ServerName MyServerHostName
ProxyPreserveHost On
ProxyRequests Off
ProxyPass / http://localhost:51058/
ProxyPassReverse / http://localhost:51058/
</VirtualHost>
Here I assume that 51058 is a non-secure(HTTP) port.
You can change the Listen port from 51058 to 80 and configure the Virtual host to use port 80

How can I use apache or nginx as frontend for a node app?

I'm trying to develop a Node.js web application, but my production environment-to-be is already hosting Apache/2.2.22. So I can't have Node use port 80, and I don't want my users to have to go to http://myapp.com:4000/.
Is there an apache module that does this, perhaps like mod_jk does this for Tomcat?
The same question goes for nginx.
mod_proxy can do that (for apache)
<VirtualHost nodejs.host.com>
ProxyRequests Off
ProxyPreserveHost On
ProxyPass / http://localhost:4000
ProxyPassReverse / http://localhost:4000
</VirtualHost>
will forward everything on that virtualhost to Node.js

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.