-1

I have a VPS with CentOS7 with httpd + php running on 80 port and let's say with domainOne.tld.

All of the web files are in /var/www/html.

Now I need to run a java application on jetty on another domain, let's say domainTwo.tld.

If I just install jetty it will be on 8080 port while httpd is on 80. They should work okay I guess, but is it possible to attach domainTwo.tld to jetty's 8080 port while it not be accessed on domainOne.tld:8080 ?

David Makogon
  • 2,768
  • 1
  • 20
  • 29
artouiros
  • 121
  • 1
  • 4
  • 4
    Set up Apache as a reverse proxy for Jetty. – Sven Jul 22 '16 at 18:38
  • I'm voting to close this question as a duplicate of [this search](https://serverfault.com/search?tab=votes&q=apache%20reverse%20proxy). It has been asked and answered many times already. – user9517 Jul 22 '16 at 20:51
  • In my defense I want to say that I can use search. The problem was that I had no clue that I have to use reverse proxy. Thanks. – artouiros Jul 22 '16 at 21:00

1 Answers1

2

Check out mod_proxy. Something like this should work.

<VirtualHost *:80>
  ServerName domainOne.tld
  #put info to point to your PHP app here

</VirtualHost>

<VirtualHost *:80>
  ServerName domainTwo.tld

  ProxyRequests Off
  ProxyPreserveHost On

  <Proxy *>
    Order deny,allow
    Allow from all
  </Proxy>

  ProxyPass / http://localhost:8080/
  ProxyPassReverse / http://localhost:8080/
</VirtualHost>
tweeks200
  • 351
  • 1
  • 3
  • 11
  • mod_proxy works, thanks. if I want to use https do I just remove the 80's port virtualhost and create one for 443 port. I'm not very good in servers. – artouiros Jul 22 '16 at 20:57
  • Yes that would work, you will also need to add a certificate and key. – tweeks200 Jul 22 '16 at 21:07
  • Hi again, I had a little problem with your example. Just saw it. I enabled `mod_proxy` in httpd.conf by writing `LoadModule proxy_module modules/mod_proxy.so` and `LoadModule proxy_http_module modules/mod_proxy_http.so` and used your virtualhost example. In servername I wrote `domainTwo.tld` and it worked but it worked and for `domainOne.tld`. So I added anotehr virtual host: ` ServerName domainOne.tld ServerAlias *.domainOne.tld ` Am I doing this right? – artouiros Jul 23 '16 at 09:10
  • Think I read your request wrong, I thought you want httpd in front of jetty which is what mod_proxy would do. I updated the example above to what I think you are trying to do. The first virtualhost is for php and the second is for jetty. – tweeks200 Jul 24 '16 at 15:43