Domain issue with tomcat - java

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>

Related

Wildcard Subdomain In SpringBoot For my Mac

I am creating a web application in which there will be multiple subdomain. Each client will be having its own subdomain. Each subdomain will have individual database. For example I am having a client abc, then it will have subdomain as abc.mydomain.com and its database name will be abc.
Now this application is created in spring boot. Here I want to configure wildcard subdomain. So how can I configure it in spring boot. For this, I had tried few solution.
I had changed my /etc/hosts and added an domain name entry in it as below
127.0.0.1 www.mydomain.com
But now I want subdomain in this. How can I do it.
I had seen somewhere that I need to configure server.xml of tomcat. In server.xml I had added below line.
<Host name="www.mydomain.com" appBase="webapps" unpackWARs="true"
autoDeploy="true">
<Alias>*.mydomain.com</Alias>
</Host>
Can you please help me with this. Also let me know incase you need more details in this.
After been working for multiple days I came to a solution for this question. As I was working for wildcard subdomain in localhost. Thus for this I need to use an external software called dnsmasq, I had executed following commands to install dnsmasq in my laptop.
brew install dnsmasq
After installing dnsmasq in my laptop I need to to configure it. For this I have to update the dnsmasq. For my case it is located at
/usr/local/etc/dnsmasq.conf
In this file I have to add few lines to configure wildcard subdomain. Lines are as below.
# Route all *.mydomain.com addresses to localhost
address=/mydomain.com/127.0.0.1
# Don't read /etc/resolv.conf or any other configuration files.
no-resolv
# Never forward plain names (without a dot or domain part)
domain-needed
# Never forward addresses in the non-routed address spaces.
bogus-priv
Next I need to restart my dnsmasq service. Command for it is as below.
sudo brew services start dnsmasq
Finally you need to create a file mydomain.com at /etc/resolver (Create folder resolver if not exists). Add below line in mydomain.com file.
nameserver 127.0.0.1
This is the complete configuration for setting up swildcard subdomain in your mac os.
For reference you can follow this link

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

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.

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

Glassfish Server Webservice behind Apache HTTP Server

Hi
We started to create our applications with J2EE. We now created a Webservice and deployed it to the Glassfish Server. We have written an apache proxy rule to access it via https://our.server.com/webservice-war (only https port is open to that server):
ProxyRequests Off
ProxyPass /webservice-war http://our.server.com:8080/webservice-war
ProxyPassReverse /webservice-war http://our.server.com:8080/webservice-war
Now everything works fine, but when we go to the to the ServiceEndpoint page (which is automatically generated) there is a link to the WSDL page:
http://our.server.com:8080/webservice-war/HostaliasSearchImplService?wsdl
which is obously wrong (Glassfish listens to port 8080). and also https is changed to http
Anyone an idea how I can fix it, that the automatically generated link is:
https://our.server.com/webservice-war/HostaliasSearchImplService?wsdl
BR, Rene
I discovered what I consider to be a very simple and elegant way to deal with the issue: use mod_substitute. Since those of us with this problem are already using Apache, and it's built in and simple, I liked this approach best.
I put a block similar to the below in one of my Apache conf files and found joy:
<Location />
AddOutputFilterByType SUBSTITUTE text/xml
Substitute "s|http://internal:8080/foo|https://external/foo|ni"
</Location>
Found the solution!
Anonym gave me a good hint about mod_jk. So here the complete configuration (for RHEL5).
First of all Download the mod_jk module for apache: http://archive.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/linux/jk-1.2.31/x86_64/
Put in in the modules directory /etc/httpd/modules and make it executeable:
chmod +x mod_jk-1.2.31-httpd-2.2.x.so
After that create /etc/httpd/conf/workers.properties:
# Define 1 real worker using ajp13
worker.list=worker1
# Set properties for worker1 (ajp13)
worker.worker1.type=ajp13
worker.worker1.host=localhost
worker.worker1.port=8009
The Port 8009 is the where the Glassfish jk connector listens (we come to that later).
No we have to configure mod_jk, therefore create the file: /etc/httpd/conf.d/mod_jk.conf with the following content:
LoadModule jk_module modules/mod_jk-1.2.31-httpd-2.2.x.so
JkWorkersFile /etc/httpd/conf/workers.properties
# Where to put jk logs
JkLogFile /var/log/httpd/mod_jk.log
# Set the jk log level [debug/error/info]
JkLogLevel debug
# Select the log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
# JkOptions indicate to send SSL KEY SIZE,
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
# JkRequestLogFormat set the request format
JkRequestLogFormat "%w %V %T"
# Send everything for context /atsi-war to worker named worker1 (ajp13)
JkMount /yourapp-war/* worker1
(This means everything from your http://apache.webserver.com/yourapp-war/ will bi redirected to Glassfish yourapp-war application context)
Important, if you are using virtual hosts on apache, you have to set the option:
JkMountCopy On
for your virtual servers. Explication:
If this directive is set to "On" in
some virtual server, the mounts from
the global server will be copied to
this virtual server, more precisely
all mounts defined by JkMount or
JkUnMount.
Now we have to create the jk connecter in glassfish:
asadmin create-http-listener --listenerport 8009 --listeneraddress 0.0.0.0 --defaultvs server jk-connector
asadmin set configs.config.server-config.network-config.network-listeners.network-listener.jk-connector.jk-enabled=true
Restart Glassfish, and everything sould work.
As for rewriting the https -> http, I'm not sure that's possible(yet) without using mod_jk, see here
, but see also this little guide
Though, generally, you'll need configure Glassfish and set http.proxyPort (and probably http.proxyHost too). Hopefully that should reflect in the autogenerated WSDL URL.
Here's 3 different ways to do this:
1
Use asadmin (in the Glassfish bin/ directory, run
asadmin create-jvm-options "-Dhttp.proxyPort=80"
asadmin create-jvm-options "-Dhttp.proxyHost=our.server.com"
2
Edit domain.xml and add under the <java-config> element
<jvm-options>-Dhttp.proxyPort=80</jvm-options>
<jvm-options>-Dhttp.proxyHost=our.server.com</jvm-options>
3.
Open the Glassfish admin web page, under Application Server -> VM Settings -> JVM Options and add these options
http.proxyPort=80
http.proxyHost=our.server.com
Setting
server-config.network-config.protocols.protocol.http-listener-1.http.server-name=MyHost:80
on GlassFish Server Open Source Edition 3.1.2.2 (build 5) solved problem to me.

Categories