Grails app running on two different domains - java

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.

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.

Configure apache to point domain to tomcat webapps root

I've a Java based web application using tomcat8 and apache2. If I access my website via an ip address it displays the application located in /opt/tomcat/webapps. If however I try and access my website via it's domain name it directs me to the default apache2 page located in /var/www/html/index.html ( which is not surprising since the DocumentRoot is set to /var/www/html in my VirtualHost, see below).
What's the correct way to point to the tomcat webapps root directory? Do I need to use JkMount?
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerAdmin webmaster#localhost
ServerName mywebsite.com
DocumentRoot /var/www/html
I resolved this by configuring a reverse proxy in Apache to serve my tomcat application.
https://wiki.apache.org/httpd/TomcatReverseProxy

Domain issue with tomcat

I have deployed a java based website on my VPS. It successfully deployed and working correctly. I have defined a redirect rule to redirect from root to sub folder. The issue right now I am facing is,
if I put domain.com -> redirects to domain.com/pages/shopIndex (shows
page correctly)
and
when I put www.domain.com -> redirects to
www.domain.com/pages/shopIndex (shows 404)
I am not understanding this strange behavior because I have added alias for domain.com to www.domain.com in my httpd.conf
This is how my virtual host file look like:
<VirtualHost 192.169.235.118:80>
ServerName domain.parentDomain.in
ServerAlias domain.com www.domain.com www.domain.parentDomain.in
DocumentRoot /path_to/domain.com
ServerAdmin admin#admin
UseCanonicalName Off
CustomLog /path_to/domain.parentDomain.in combined
</VirtualHost>
Can anyone help me to find the solution?
I got the solution for this problem, there is Alias tag for server.xml file where we can put Alias for host we want to represent.
This is how I solved the issue (in server.xml inside host tag):
<Alias>www.domain.com</Alias>

Mapping domains to Tomcat Apps

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

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/

Categories