Spring Boot Project work with Apache Http Server - apache

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>

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>

How do I send requests to two processes in Apache2?

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>

Apache reverse proxy match requests

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/

Start two Play! application on same name server

I'm trying to run two different web application on the same server, with the same domain name, like :
www.example.com/app1
www.example.com/app2
The applications are developed using Play! framework, and I'm using Apache as a reverse proxy. I tried to follow the online guide, set up the virtual host and etc..., but nothing seem to works, only the first app is reacheble, while the second isn't.
This is as far as I got untill now with my apache config file :
<VirtualHost *:80>
ProxyPreserveHost On
DocumentRoot "/home/App1/"
ServerName http://www.example.com/app1
ProxyPass /excluded !
ProxyPass / http://127.0.0.1:9000/app1
ProxyPassReverse / http://127.0.0.1:9000/app1
LogLevel debug
</VirtualHost>
<VirtualHost *:80>
ProxyPreserveHost On
DocumentRoot "/home/App2"
ServerName http://www.example.com/app2
ProxyPass /excluded !
ProxyPass / http://127.0.0.1:8000/app2
ProxyPassReverse / http://127.0.0.1:8000/app2
LogLevel debug
</VirtualHost>
Route, code and everithing are correct, it's just that I can't get these apps work together.
(I also tried to implement the load balacer showed on the online guide, but it didn't work)
Thanks.
I don't think you can have two virtual hosts with the same host name - that doesn't make sense, virtual hosts are for serving different host names, for example, for serving foo.example.com and bar.example.com.
I think what you want is something roughly like this:
<VirtualHost *:80>
ProxyPreserveHost On
ServerName www.example.com
DocumentRoot /some/path/to/something
ProxyPass /excluded !
ProxyPass /app1 http://127.0.0.1:9000/app1
ProxyPassReverse /app1 http://127.0.0.1:9000/app1
ProxyPass /app2 http://127.0.0.1:8000/app2
ProxyPassReverse /app2 http://127.0.0.1:8000/app2
LogLevel debug
</VirtualHost>
James' answer is correct, you just need to fit it to your needs, I shoot that works out of the box:
<VirtualHost *:80>
ProxyPreserveHost On
ServerName www.example.com
ProxyPass /app1 http://127.0.0.1:9000/
ProxyPassReverse /app1 http://127.0.0.1:9000/
ProxyPass /app2 http://127.0.0.1:8000/
ProxyPassReverse /app2 http://127.0.0.1:8000/
</VirtualHost>
Note, that you will need to prefix EVERY route in your apps to reflect the folder path with app1 and app2, like:
foo site
bar site

Apache redirect to another port

I've struggled with this for some time and am definitely doing something wrong.
I have Apache server and a JBoss server on the same machine. I'd like to redirect traffic for mydomain.example to JBoss localhost:8080/example. The DNS is currently setup for mydomain.example and it will go straight to port 80 when entered into the browser.
My question is how do I redirect to a different port when a certain domain name comes to Apache (in this case, mydomain.example)?
<VirtualHost ip.addr.is.here>
ProxyPreserveHost On
ProxyRequests Off
ServerName mydomain.example
ProxyPass http://mydomain.example http://localhost:8080/example
ProxyPassReverse http://mydomain.example http://localhost:8080/example
</VirtualHost>
After implementing some suggestions:
Still not forwarding to port 8080
<VirtualHost *:80>
ProxyPreserveHost On
ProxyRequests Off
ServerName mydomain.example
ServerAlias www.mydomain.example
ProxyPass http://mydomain.example http://localhost:8080/example
ProxyPassReverse http://mydomain.example http://localhost:8080/example
</VirtualHost>
You should leave out the domain http://example.com in ProxyPass and ProxyPassReverse and leave it as /. Additionally, you need to leave the / at the end of example/ to where it is redirecting. Also, I had some trouble with http://example.com vs. http://www.example.com - only the www worked until I made the ServerName www.example.com, and the ServerAlias example.com. Give the following a go.
<VirtualHost *:80>
ProxyPreserveHost On
ProxyRequests Off
ServerName www.example.com
ServerAlias example.com
ProxyPass / http://localhost:8080/example/
ProxyPassReverse / http://localhost:8080/example/
</VirtualHost>
After you make these changes, add the needed modules and restart apache
sudo a2enmod proxy && sudo a2enmod proxy_http && sudo service apache2 restart
I solved this issue with the following code:
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
<VirtualHost *:80>
ProxyPreserveHost On
ProxyRequests Off
ServerName myhost.example
ServerAlias www.myhost.example
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
</VirtualHost>
I also used:
a2enmod proxy_http
I wanted to do exactly this so I could access Jenkins from the root domain.
I found I had to disable the default site to get this to work. Here's exactly what I did.
$ sudo vi /etc/apache2/sites-available/jenkins
And insert this into file:
<VirtualHost *:80>
ProxyPreserveHost On
ProxyRequests Off
ServerName mydomain.example
ServerAlias mydomain
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
</VirtualHost>
Next you need to enable/disable the appropriate sites:
$ sudo a2ensite jenkins
$ sudo a2dissite default
$ sudo service apache2 reload
Found this out by trial and error. If your configuration specifies a ServerName, then your VirtualHost directive will need to do the same. In the following example, awesome.example.com and amazing.example.com would both be forwarded to some local service running on port 4567.
ServerName example.com:80
<VirtualHost example.com:80>
ProxyPreserveHost On
ProxyRequests Off
ServerName awesome.example.com
ServerAlias amazing.example.com
ProxyPass / http://localhost:4567/
ProxyPassReverse / http://localhost:4567/
</VirtualHost>
I know this doesn't exactly answer the question, but I'm putting it here because this is the top search result for Apache port forwarding. So I figure it'll help somebody someday.
This might be an old question, but here's what I did:
In a .conf file loaded by Apache:
<VirtualHost *:80>
ServerName something.com
ProxyPass / http://localhost:8080/
</VirtualHost>
Explanation: Listen on all requests to the local machine's port 80. If I requested "http://something.com/somethingorother", forward that request to "http://localhost:8080/somethingorother". This should work for an external visitor because, according to the docs, it maps the remote request to the local server's space.
I'm running Apache 2.4.6-2ubuntu2.2, so I'm not sure how the "-2ubuntu2.2" affects the wider applicability of this answer.
You have to make sure that the proxy is enabled on the server. You can do so by using the following commands:
a2enmod proxy
a2enmod proxy_http
service apache2 restart
If you don't have to use a proxy to JBoss and mydomain.example:8080 can be "exposed" to the world, then I would do this.
<VirtualHost *:80>
ServerName mydomain.example
Redirect 301 / http://mydomain.example:8080/
</VirtualHost>
Just use a Reverse Proxy in your apache configuration (directly):
ProxyPass /foo http://foo.example.com/bar
ProxyPassReverse /foo http://foo.example.com/bar
Look here for apache documentation of how to use the mod
My apache listens to 2 different ports,
Listen 8080
Listen 80
I use the 80 when i want a transparent URL and do not put the port after the URL
useful for google services that wont allow local url?
But i use the 8080 for internal developing where i use the port as a reference for a "dev environment"
You need 2 things:
Add a ServerAlias www.mydomain.example to your config
change your proxypass to ProxyPassMatch ^(.*)$ http://localhost:8080/example$1, to possibly keep mod_dir and trailing slashes from interfering.
Apache supports name based and IP based virtual hosts. It looks like you are using both, which is probably not what you need.
I think you're actually trying to set up name-based virtual hosting, and for that you don't need to specify the IP address.
Try < VirtualHost *:80> to bind to all IP addresses, unless you really want ip based virtual hosting. This may be the case if the server has several IP addresses, and you want to serve different sites on different addresses. The most common setup is (I would guess) name based virtual hosts.
This is working in ISPConfig too. In website list get inside a domain, click to Options tab, add these lines: ;
ProxyPass / http://localhost:8181/
ProxyPassReverse / http://localhost:8181/
Then go to website and wolaa :) This is working HTTPS protocol too.
Try this one-
<VirtualHost *:80>
ProxyPreserveHost On
ProxyRequests Off
ServerName www.adminbackend.example.com
ServerAlias adminbackend.example.com
ProxyPass / http://localhost:6000/
ProxyPassReverse / http://localhost:6000/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
This is how I redirected part of the requests to one url and rest to another url:
<VirtualHost *:80>
ProxyPreserveHost On
ProxyRequests Off
ServerName localhost
ProxyPass /context/static/content http://localhost:80/web/
ProxyPassReverse /context/static/content http://localhost:80/web/
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
</VirtualHost>
All are excellent insights to accessing ports via domain names on virtual servers. Do not forget, however, to enable virtual servers; this may be commented out:
NameVirtualHost *:80
<Directory "/home/dawba/www/">
allow from all
</Directory>
We run WSGI with an Apache server at the domain sxxxx.com and a golang server running on port 6800. Some firewalls seem to block domain names with ports. This was our solution:
<VirtualHost *:80>
ProxyPreserveHost On
ProxyRequests Off
ServerName wsgi.sxxxx.example
DocumentRoot "/home/dxxxx/www"
<Directory "/home/dxxx/www">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
ScriptAlias /py/ "/home/dxxxx/www/py/"
WSGIScriptAlias /wsgiprog /home/dxxxx/www/wsgiprog/Form/Start.wsgi
</VirtualHost>
<VirtualHost *:80>
ProxyPreserveHost On
ProxyRequests Off
ServerName sxxxx.com
ServerAlias www.sxxxx.com
ProxyPass / http://localhost:6800/
ProxyPassReverse / http://localhost:6800/
</VirtualHost>