How to have Apache server port 8080 display content from localhost:3080 - apache

So I have an application the is bound to localhost:3080. When I locally visit "localhost:3080" the application displays in the browser.
I also have an apache server setup listening to the publicIP:8080.
When I visit the publicIP from the outside world, publicIP:8080 loads up.
How can I have it so that when I visit publicIP:8080, the contents of localhost:3080 are displayed onto it?
Is there a way to forward the contents of localhost:3080 to publicIP:8080?

You can create an apache proxy.For example :
<VirtualHost *:8080>
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:3080/
ProxyPassReverse / http://127.0.0.1:3080/
</VirtualHost>
You will also need to do :
a2enmod proxy
a2enmod proxy_http
service apache2 restart
See more informations there : https://www.digitalocean.com/community/tutorials/how-to-use-apache-http-server-as-reverse-proxy-using-mod_proxy-extension

I assume your application at localhost:3080 acts as a http server.
Then you would simply
ProxyPass "/" "http://localhost:3080/"
Generally its better to use ProxyPass to handle only special locations
<Location "/myCoolApp/">
ProxyPass "http://localhost:3080/"
</Location>
Then if you request http://publicIP:8080/myCoolApp/XYZ your application #3080 will receive the request on URL /XYZ.

Related

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 and multiple tomcats proxy

I have 1 apache server and two tomcat servers with two different applications. I want to use the apache as a proxy so that the user can access the application from the same url using different paths.
e.g.:
localhost/app1 --> localhost:8080/app1
localhost/app2 --> localhost:8181/app2
I tried all 3 mod proxy of apache (mod_jk, mod_proxy_http and mod_proxy_ajp) but the first application is working, whilst the second is not accessible.
This is the apache configuration I'm using:
ProxyPassMatch ^(/.*\.gif)$ !
ProxyPassMatch ^(/.*\.css)$ !
ProxyPassMatch ^(/.*\.png)$ !
ProxyPassMatch ^(/.*\.js)$ !
ProxyPassMatch ^(/.*\.jpeg)$ !
ProxyPassMatch ^(/.*\.jpg)$ !
ProxyRequests Off
ProxyPass /app1 ajp://localhost:8009/
ProxyPassReverse /app1 ajp://localhost:8009/
ProxyPass /app2 ajp://localhost:8909/
ProxyPassReverse /app2 ajp://localhost:8909/
With the above, I manage to view the tomcat root application using localhost/app1, but I
get "Service Temporarily Unavailable" (apache error) when accessing app2.
I need to keep the tomcat servers separate because I need to restart one of the applications often and it is not an option to save both apps on the same tomcat.
Can someone point me out what I'm doing wrong?
Thank you all.

Apache Redirect to two different servers bases on URL

I want to do the following:
I've a server A (http://server-a:9000/) and the server B (http://server-b:8000/). Additionally I've installed an Apache running on port 80.
When I access the apache with http://localhost/product I want to pass this request to http://server-a:9000/product
and
when I access the apache with http://localhost/details I want to pass the request to http://server-b:8000/details.
I'v got this working with the following configuration:
ProxyPass /product http://server-a:9000/product
ProxyPassReverse /product http://server-a:9000/product
ProxyPass /details http://server-b:8000/product
ProxyPassReverse /details http://server-b:8000/product
But with this configuration the original URL http://localhost/product is replaced by http://server-a:9000/product.
How can I configure my Apache so that it doesn't replace the URL? The displayed URL should always be http://localhost/product.
Thank you in advance
Torben

What are my options to deploy Go applications alongside PHP applications?

What I'm basically trying to accomplish is having my main website running a CMS written in Go. This will be located at www.example.com.
I also have applications written in PHP located in directories, such as www.example.com/clients/
How can I serve example.com/clients using Apache/PHP while serving example.com using Go built-in web server?
Via mod_proxy in Apache2, you can proxy different paths into different destinations at localhost or anywhere else accessible by your server, including within your local network (if your server can access it).
For this you would use ProxyPass (Apache2 Docs for ProxyPass, which is very useful reading) like the example below:
<VirtualHost *:80>
ServerName some.example.host.xyz
DocumentRoot /var/www/your-document-root
Alias /clients/ /var/www/clients/
ProxyPass /clients/ !
ScriptAlias /something-using-cgi/ /var/www/cgi-stuff/
ProxyPass /something-using-cgi/ !
ProxyPreserveHost On
ProxyPass / http://localhost:9876/
ProxyPassReverse / http://localhost:9876/
ProxyPass /elsewhere/ http://elsewhere.example.host.xyz:1234/
ProxyPassReverse /elsewhere/ http://elsewhere.example.host.xyz:1234/
</VirtualHost>
You'll want to be sure that you set your proxy security such that external users can't use your reverse proxy as a forward proxy, too. You can do that via ProxyRequests as described in the official Apache2 docs. The way I did this on a server is to put this in your server-wide config (you should verify on your own that this is secure enough):
# disables forward proxy
ProxyRequests Off
Andrew Gerrand has a good blog post about this for nginx but the principle is the same for Apache.
You want to set up Apache as a reverse proxy for requests coming in for the Go application.
For Apache you want to look at mod_proxy

Mapping address to multiple tomcat instances

I have 3 tomcat instances running on Windows Server 2008 machine. Each one with one app:
http://host:8080/app0
http://host:8081/app1
http://host:8082/app2
How I can configure my server to map an address without the port number?
http://host/app0
http://host/app1
http://host/app2
Is it a tomcat configuration or something with DNS?
Thanks.
Ok, I tried the following:
Set up the Apache 2.2
Configure httpd.conf loading proxy modules
And add a proxy module configuration:
ProxyRequests Off
ProxyPass /app1 http://machine:8081/app
ProxyPassReverse /app1 http://machine:8081/app
<Location "/app">
Order allow,deny
Allow from all
</Location>
Now the redirect works well local in the machine. But it doesn't works when I try access from another machine in the same network. (this another machine can ping 'machine' host. And I tried putting the ip number too).
You can use nginx (http://nginx.org/en/docs/) as proxy for example.
Try simply (no load balancing etc.):
server {
listen here.your.ip:80/YourApp;
location / {
root /path/to/your/webapp;
proxy_pass http://host:8080/YourApp;
}
}
Same way for other ports
It is quite common to use multiple Tomcats behind Apache to do load balancing. While this is not load balancing the principle is the same. Instead of having one application with 3 load-balanced Tomcat workers, you would have 3 applications with 1 tomcat worker each.
You can find the tomcat documentation here: http://tomcat.apache.org/connectors-doc/
Try mod proxy configuration on below code in httpd:
ProxyPass /app0 http://localhost:8080/app0/
ProxyPassReverse /app0 http://localhost:8080/app0/
ProxyPass /app1 http://localhost:8081/app1/
ProxyPassReverse /app1 http://localhost:8081/app1/
ProxyPass /app2 http://localhost:8082/app2/
ProxyPassReverse /app2 http://localhost:8082/app2/