How do I send requests to two processes in Apache2? - apache

I got two servers, a custom Rust server I've created, listening to port 4848, and a Gitea server listening at 3000. I can connect to both of these just fine if I input the IP and port directly, but obviously this is not ideal. How can I direct *.domain.exmaple to the process at 4848, and gitea.domain.example at 3000?
I'm using Ubuntu 22
Thanks!

Finally managed to find a solution. I edited my main configuration file to this
<VirtualHost *:80>
ServerAdmin admin#email
ServerName gitea.domain.example
ProxyPreserveHost On
# setup the proxy
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
</VirtualHost>
<VirtualHost *:80>
ServerAdmin admin#email
ServerName domain.example
ServerAlias *.domain.example
ProxyPreserveHost On
# setup the proxy
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
ProxyPass / http://localhost:4848/
ProxyPassReverse / http://localhost:4848/
</VirtualHost>

Related

Setting up reverse proxy using Apache on Windows Server 2008 R2

I am trying to setup Reverse Proxy using Apache Server 2.4.23 for two different domain. One domain is pointing to localhost site and other is pointing to other server web site. Here are my configuration
Listen 111.111.11.222:80
Listen 111.111.11.333:80
<VirtualHost 111.111.11.222:80>
ServerName myapp.com
ErrorLog "logs/app_error_log"
CustomLog "logs/app_access_log" common
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://111.111.11.222:8090/
ProxyPassReverse / http://111.111.11.222:8090/
<Location />
Order allow,deny
Allow from all
</Location>
</VirtualHost>
<VirtualHost 111.111.11.333:80>
ServerName myauditor.com
ProxyRequests Off
# ProxyPreserveHost On
ErrorLog "logs/auditor_error_log"
CustomLog "logs/auditor_access_log" common
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://www.mycompamy.com/
ProxyPassReverse / http://www.mycompany.com/
</VirtualHost>
In these settings, first "myapp.com" is working fine as needed. However when I try myauditor.com then instead of acting it as reverse proxy, it is redirecting to www.mycompany.com.
In myauditor.com setting, if I un-comment and use ProxyPreserveHost On then myauditor.com start giving me error
Invalid URL
The requested URL "http://%5bNo%20Host%5d/", is invalid.
Reference #9.2d3d6b68.1485193636.126886bd
I am new to Apache so I am not sure, when ProxyPreserveHost is working fine in first VirtualHost then why it causing issue in second VirtualHost.

502 Proxy Error - MeteorJS on Apache

I am new to Meteor, and I have an existing server that is hosting a few websites (CentOS). I use Apache to serve the sites and wanted to have a Meteor app running on a subdomain.
Here is what I have for the Meteor site in httpd.conf:
<VirtualHost *:80>
ServerName www.subdomain.domain.net
ServerAlias subdomain.domain.net
DocumentRoot /var/www/my_meteor_directory/testapp
ProxyRequests Off
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
ProxyPass / http://127.0.0.1:3000
ProxyPassReverse / http://127.0.0.1:3000
</VirtualHost>
I also have this at the bottom of my httpd.conf file:
<Proxy *>
Allow from 127.0.0.1
</Proxy>
ProxyPreserveHost On
ProxyPassMatch ^/(.+\.cf[cm])(/.*)?$ ajp://localhost:3000/$1$2
I set the app to run on port 3000 and when I try to hit it in the browser (subdomain.domain.net) I get these 502 errors:
Any suggestions?
Try this...
<VirtualHost *:80>
ServerName meteorapp.example.com
ProxyRequests off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Location />
ProxyPass http://localhost:8080/
ProxyPassReverse http://localhost:8080/
</Location>
</VirtualHost>
then reload the server

How can I setup apache to proxy for two different tomcats on the same server?

I have to have two different tomcats on the same server both to be targeted by different domain names. I was wondering if it is possible for apache to proxy to both. I haven't found any documentation that with explanation to this solution yet.
I have below an example virtual host of the two I have on the server which proxies for the single tomcat instance so far:
<VirtualHost *:80>
ServerName tinderbox.mycompany.com
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
</VirtualHost>
Something like
<VirtualHost *:80>
ServerName tinderbox.mycompany.com
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
</VirtualHost>
<VirtualHost *:80>
ServerName othername.mycompany.com
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://localhost:9090/
ProxyPassReverse / http://localhost:9090/
</VirtualHost>
Essentially, repeat the VirtualHost block, change the server name so the block applies to your second domain name and change the target of the ProxyPass to whatever ports the second Tomcat instance is using.

Apache virtual host to tomcat server

I would like to set apache to root to my tomcat server in the same machine.Apache is listening to port 80 and tomcat to 9090. The dns name of my service is example.com.gr the machine ip is something like "150.111.111.11" and in the httpd file i wrote this
NameVirtualHost *:80
<VirtualHost *:80>
<ServerName example.com.gr
ErrorLog logs/example.com.gr.gr_error_log
TransferLog logs/example.com.gr.gr_access_log
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://150.111.111.11:9090/
ProxyPassReverse / http://150.111.111.11:9090/
<Location />
Order allow,deny
Allow from all
</Location>
</VirtualHost>
But when i hit example.com.gr i get (110) Connection timed out,but if i hit example.com.gr:9090 i see my portal.Any ideas?

Issues Setting up a reverse proxy in Apache

My roommate and I each have a separate webserver we are trying to set up. We are trying to use mod_proxy so that his server will forward requests to my machine (we have two seperate machines behind one router) based on the server name. I've given the basics of what we have in our apache config currently but we are getting a 403 Forbidden error when trying to access the second domain (the first, www domain, works fine).
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /var/www
ServerName www.<domain1>.com
</VirtualHost>
<VirtualHost *:80>
ProxyPreserveHost On
ProxyPass / http://<IP addr of other box>:80
ProxyPassReverse / http://<IP addr of other box>:80
ServerName <dummydomain>.gotdns.com
</VirtualHost>
Your mods-enabled/proxy.conf might be blocking any proxy requests (it's deny all by default). It should include the following instead:
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
EDIT: Also make sure that the mod_proxy submodules are sym linked into mods-enabled (in this case, the http sub module which is mods-available/proxy_http.load)
Just put both routes:
<VirtualHost *:80>
DocumentRoot "/app/"
ProxyPreserveHost On
ProxyRequests Off
ServerName app.yourdomain.com
ProxyPass /app http://yourIP:yourPort/app/
ProxyPassReverse /app http://yourIP:yourPort/app/
ProxyPass / http://yourIP:yourPort/app/
ProxyPassReverse / http://yourIP:yourPort/app/
</VirtualHost>
<Location "/app/" >
ProxyPass "http://yourIP:yourPort/app/"
ProxyPassReverse "http://yourIP:yourPort/app/"
ProxyPassReverseCookiePath "/app/" "/app/"
ProxyHTMLEnable Off
ProxyHTMLExtended On
ProxyHTMLURLMap "/app/" "/app/"
Order allow,deny
Allow from all
</Location>
This worked form me