Apache reverse proxy match requests - apache

My server hosts two web services: WordPress(on Port 8080) and Flask(on Port 8081). I am setting up a reverse proxy as I want any requests start with /admin goes to Flask and all others go to Wordpress.
For example:
http://aa.mcmaster.ca/admin/aa Goes to Port 8080
http://aa.mcmaster.ca/page1 Goes to Port 8081
http://aa.mcmaster.ca/page1 Goes to Port 8081
My setting is:
<VirtualHost *:80>
DocumentRoot /wordpress/wp-content
SSLProxyEngine On
ProxyPreserveHost On
ServerName aa.mcmaster.ca
ProxyRequests off
ProxyPass /admin http://aa.mcmaster.ca:8080/
ProxyPassReverse /admin http://aa.mcmaster.ca:8080/
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /wordpress/wp-content
SSLProxyEngine On
ProxyPreserveHost On
ServerName aa.mcmaster.ca
ProxyRequests off
ProxyPass /http://aa.mcmaster.ca:8081/
ProxyPassReverse / http://aa.mcmaster.ca:8081/
</VirtualHost>
It doesn't work. I am stuck on how to set up to matchs requests other than /admin. Can I get some help?
Thanks!

Use below ProxyPass in a single VirtualHost and test.
ProxyPass /admin/ http://aa.mcmaster.ca:8080/
ProxyPassReverse /admin/ http://aa.mcmaster.ca:8080/
ProxyPass / http://aa.mcmaster.ca:8081/
ProxyPassReverse / http://aa.mcmaster.ca:8081/

Related

Apache2 and Graylog

i need to solve quickly this problem.
I have a apache2 running on server and a graylog installed and running and i cannot reach the localhost:9000 where the graylog is running. I try to configure virtualhost, but i can't configure correctly.
i try this config, and many others, but no one help me.
<VirtualHost *:80>
ProxyPreserveHost On
ProxyRequests Off
ServerName www.graylog.xxxxxx.com
ServerAlias example.com
ProxyPass / http://127.0.0.1:9000/
ProxyPassReverse / http://127.0.0.1:9000/
</VirtualHost>
<VirtualHost *:80>
ProxyPreserveHost On
ProxyRequests Off
ServerName www.graylog.xxxxxx.com
ServerAlias example.com
ProxyPass / http://127.0.0.1:9000/
ProxyPassReverse / http://127.0.0.1:9000/
</VirtualHost>

Spring Boot Project work with Apache Http Server

I have two project that write with spring boot, and have separate port number.
server.port: 23100
server.port: 23101
now, I want to deploy the two project into one server and shard the same port 80,
How should I do to support this case ?
I know it can use Apache Http Server to support PHP etc. how to do this will Spring Boot ?
Update
thanks #HeadBangingSloth give this solution, general idea is to redirect 80 port to local port number according to domain name.
create vhost.conf file in /etc/httpd/conf.d/ folder
add following content according to your real case.
restart http server via service httpd restart
<VirtualHost *:80>
ProxyPreserveHost On
ProxyRequests Off
ServerName www.app1.com
ServerAlias app1.com
ProxyPass / http://localhost:23100/
ProxyPassReverse / http://localhost:23100/
</VirtualHost>
<VirtualHost *:80>
ProxyPreserveHost On
ProxyRequests Off
ServerName www.app2.com
ServerAlias app2.com
ProxyPass / http://localhost:23101/
ProxyPassReverse / http://localhost:23101/
</VirtualHost>
I would suggest looking at this question here Apache redirect to another port
If you deploy your applications to your sever, you can set up your VirtualHosts in Apache to pass the incoming connections along
<VirtualHost *:80>
ProxyPreserveHost On
ProxyRequests Off
ServerName www.app1.com
ServerAlias app1.com
ProxyPass / http://localhost:23100/
ProxyPassReverse / http://localhost:23100/
</VirtualHost>
<VirtualHost *:80>
ProxyPreserveHost On
ProxyRequests Off
ServerName www.app2.com
ServerAlias app2.com
ProxyPass / http://localhost:23101/
ProxyPassReverse / http://localhost:23101/
</VirtualHost>

Virtual host with XAMP and APPSERVER

I have XAMPP and Appserver installed in one server (The first listens port 8080 and the second listens port 80).
I have a domain: example.com
I have this in APPSERV:
<VirtualHost 1.2.3.4:80>
ServerName example.com
DirectoryIndex index.php index.html
DocumentRoot "C:/appserv/www/folder"
</VirtualHost>
Is there a way so I can send that request to port 8080?
Here is a simplified version of how I accomplished it with ProxyPreserveHost
<VirtualHost www.example.com:80>
ProxyPreserveHost On
ProxyRequests Off
ServerName www.example.com
ServerAlias example.com
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
</VirtualHost>

Is it possible to use ProxyPass with only one ip address

I am looking to achieve this configuration. So I tried this but the server is allways looking for server_test and server_prod in the htdocs under Apache. What I want is to redirect the request to the Tomcat server. If I use different ports without the /server_test and /server_prod, it worked but it's not what I wanted.
<virtualhost mydomaine.com/server_test:80>
ServerName mydomaine.com
ProxyRequests Off
ProxyPass / ajp://internalIp:8008/
ProxyPassReverse / http://mydomaine.com/server_test/
ProxyPassReverseCookiePath / /
</virtualhost>
<virtualhost mydomaine.com/server_prod:80>
ServerName mydomaine.com
ProxyRequests Off
ProxyPass / ajp://internalIp:8009/
ProxyPassReverse / http://mydomaine.com/server_prod/
ProxyPassReverseCookiePath / /
</virtualhost>
Any help would be appreciated
Try this:
<virtualhost mydomaine.com:80>
ServerName mydomaine.com
ProxyRequests Off
ProxyPass /server_test ajp://internalIp:8008/
ProxyPass /server_prod ajp://internalIp:8009/
ProxyPassReverse /server_test ajp://internalIp:8008/
ProxyPassReverse /server_prod ajp://internalIp:8009/
</virtualhost>
However, you would not be able to use ProxyPassReverseCookiePath, because both Tomcat sites would set cookies with / as the path.
To make it work as I believe you want, you need to have two separate VirtualHosts. If you only have one IP address, you need to use name-based virtual hosts.
For example, add a subdomain test.mydomaine.com that has the same IP address as mydomaine.com. Then use this configuration:
NameVirtualHost mydomaine.com:80
<virtualhost mydomaine.com:80>
ServerName mydomaine.com
ProxyRequests Off
ProxyPass / ajp://internalIp:8009/
ProxyPassReverse / ajp://internalIp:8009/
</virtualhost>
<virtualhost mydomaine.com:80>
ServerName test.mydomaine.com
ProxyRequests Off
ProxyPass / ajp://internalIp:8008/
ProxyPassReverse / ajp://internalIp:8008/
</virtualhost>
You can then access your production site at http://mydomaine.com/ and your test site at http://test.mydomaine.com/.

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