Mapping domains to Tomcat Apps - java

I have a server with CentOS and zpanel installed. Zpanel installed "Apache Httpd" along many other modules. I have been hosting multiple domains without any issue.
I have two issues:
Remove port 8080 and direct all calls to 80.
Appropriate domain for each tomcat app, as well as my existing sites running independently on Apache Http.
I installed apache tomcat 8 and deployed multiple applications and I can access my applications like
http://example:8080/app1
http://example:8080/app2
http://example:8080/app3
What I want is that my tomcat apps are mapped to my domains, such that
http://example:8080/app1 => http://www.app1.com
http://example:8080/app2 => http://www.app2.com
http://example:8080/app3 => http://www.app3.com
I did tried this tutorial which somewhat does trick but not exactly what I want. i.e. after performing the steps he mentioned when I opened my example.com it redirected to my tomcat app like: example.com/app1. [It did removed 8080 and redirected to correct app] BUT if the app from the end is changed i.e. app1 is changed to someother project that is been hosting by tomcat then that project is opened.
Edit:
My virtual host file is
# DOMAIN: app1.com
<virtualhost *:80>
ServerName app1.com
ServerAlias app1.com www.app1.com
RewriteEngine On
RewriteRule ^/$ app1/ [R=301]
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
ProxyRequests Off
ProxyPreserveHost On
ProxyPass /app1 http://localhost:8080/app1
ProxyPassReverse /app1 http://localhost:8080/app1
ErrorLog "/var/zpanel/logs/domains/zadmin/app1.com-error.log"
CustomLog "/var/zpanel/logs/domains/zadmin/app1.com-access.log" combined
CustomLog "/var/zpanel/logs/domains/zadmin/app1.com-bandwidth.log" common
</virtualhost>
Update 1
I tried this as well, but of no use. Am I missing something? please guide.

Have you configured properly your http server ?
For example in your apache2.conf or httpd.conf
#LoadModule directives
LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
LoadModule proxy_http_module /usr/lib/apache2/modules/mod_proxy_http.so
<VirtualHost *:80>
ServerName www.example.com
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://example.com:8080/app1
ProxyPassReverse / http://example.com:8080/app1
ProxyHTMLURLMap / /app1/
<Location />
Order allow,deny
Allow from all
</Location>
</VirtualHost>

After 2 Days of hard search and lots of tests I was finally able to map my domain to tomcat app. Many thanks to these two guides mod_jk installation and vhost/httpd/tomcat

Related

URL Rewriting not working with Tomcat8 running on ElasticBeanStalk

We've got a Java server running on Tomcat8 on AWS ElasticBeanStalk. The project contains an AngularJS webapp as frontend.
Our frontend webapp is accessible by www.domain.com/webappName. I put a .conf file in .ebextensions/httpd/conf.d in my root directory.
Here's the content of my conf.d (rule redirect to a new url with new version of frontend, in Angular7)
<VirtualHost *:80>
LoadModule rewrite_module modules/mod_rewrite.so
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/webappname/index\.html
RewriteRule ^webappname/index\.html(.*)$ https://redirect-domain.com/$1 [R=301,L]
<Proxy *>
Require all granted
</Proxy>
ProxyPass / http://localhost:8080/ retry=0
ProxyPassReverse / http://localhost:8080/
ProxyPreserveHost on
ErrorLog /var/log/httpd/elasticbeanstalk-error_log
</VirtualHost>
But rewriting not working. I tested my rule in localhost and on an online simulator and it was working fine. But when we deploying our War file on AWS ElasticBeanStalk, it's not working.
Do you know why ? It's look like the configuration file is bypassed. I tried with AllowOverride All but it doesnt work.
Our ElasticBeanStalk is running with Tomcat8, Java8 and Apache 3.3.2.

Grails app running on two different domains

I'm trying to make grails app run under two different domains - test.com/myapp and test.org/myapp. host in Config.groovy url is pointing to https://test.com/myapp What happens is when I go to test.org/myapp it goes properly to the home page and when I'm trying to login it redirects to the first domain. I guess it's something to be with spring security and path generating. What are my options in order to fix that?
Here is my myapp.conf but if you need additional data pls let me know in comments
Alias /.well-known/acme-challenge/ "/var/www/html/certbot/.well-known/acme-challenge/"
<Directory "/.well-known/acme-challenge/">
Options -Indexes -MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
<VirtualHost *:80>
ServerName test.com
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</VirtualHost>
<VirtualHost *:443>
ServerName test.com
ServerAlias www.test.com
DocumentRoot /var/www/html/honeypot/
RewriteEngine On
php_flag engine off
RemoveHandler .cgi .php .php3 .php4 .php5 .phtml .pl .py .pyc .pyo
JkMount /* worker1
JkUnMount /myapp/files/* worker1
Alias "/myapp/files" "/var/www/myapp/files"
<Directory "/myapp/files">
allow from all
Options -Indexes
AllowOverride None
</Directory>
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/test.com/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/test.com/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/test.com/chain.pem
SSLProxyEngine on
ProxyPreserveHost On
ProxyPassMatch ^/myap(.+)$ !
ProxyPass / https://myserver.com/
ProxyPassReverse / https://myserver.com/
</VirtualHost>
UPDATE
grails.serverURL = https://test.com/myapp
Perhaps you should post your configuration for spring-security. Assuming it is that problem, there are different ways to tackle it. One is that you can set external configuration in Grails applications using grails.config.locations (see http://docs.grails.org/2.5.4/guide/single.html#configExternalized) and then you override the application settings for Spring Security within an external file on your server that the grails.config.locations is referencing.
This allows you to manage the application configuration separately, but deploy the same war. You could then manage the external files by some configuration management system, such as Puppet.

Removing app name from url in proxypassreverse setup

I have been able to map my application to the domain in a manner I found after doing some research (copy-paste) on internet.
<VirtualHost *:80>
ServerName example.com
ProxyPass /MyApp http://localhost:8080/MyApp
ProxyPassReverse /MyApp http://localhost:8080/MyApp
ProxyPassReverseCookieDomain localhost example.com
ProxyPreserveHost On
RewriteEngine on
RewriteRule ^/$ http://example.com/MyApp
</VirtualHost>
The rewrite works fine and whenever I open example.com it redirects to example.com/MyApp . My query is, how can I make it not redirect and deliver the MyApp at example.com/ without any redirect. Just plain simple mapping of the MyApp to the root of the domain. The rewrite works fine, but certainly don't want app name in url.
Rename your war file to ROOT.war to make it the root webapp in Tomcat. Then adjust the paths accordingly in the Apache config:
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/

Apache2 Proxy WebSocket Connections?

System: ubuntu 12.04LTS
I use Apache as Proxy server for my Tomcat7 webserver.
For Apache as Proxy I activated the modules:
sudo a2enmod proxy
sudo a2enmod proxy_http
Then I edit the /etc/apache2/sites-available/default as:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ProxyRequests Off
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
<Location "/">
Order allow,deny
Allow from all
</Location>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
I am using Websockets so I need to enable them. How can I do that in the Apache Proxy server?
Chrome shows me this error:
WebSocket connection to 'ws://www.myapp.com/socket/848df2e62fcf93e1b3?X-Atmosphere-tracking-iā€¦Date=0&Content-Type=application/json;%20charset=UTF-8&X-atmo-protocol=true'
failed: Unexpected response code: 200
You are seeing that error likely because your version of Apache does not support HTTP 1.1. To configure your Apache to support websockets, try following this:
https://serverfault.com/questions/290121/configuring-apache2-to-proxy-websocket
EDIT: Removing remainder of post as it is off subject

PhpMyAdmin not access able after setting tomcat on port 80

I just set tomcat on port 80
by adding this on /etc/httpd/conf/httpd.conf
<VirtualHost *:80>
ServerAdmin tomcat#something.com
ServerName something.com
ServerAlias www.something.com
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
ProxyPass / http://something.com:8080/
ProxyPassReverse / http://something.com:8080/
ErrorLog logs/something.com-error_log
CustomLog logs/something.com-access_log common
</VirtualHost>
But now i am trying to access something.com/phpMyadmin
It is redirecting to something.com:8080/something.com
which is a wrong path
Please help
Try adding this line right before your existing ProxyPass:
ProxyPass /phpMyadmin !
It tells Apache not to proxy this path to Tomcat. Everything else will be proxied.

Categories