CSS & images breaking after mapping application deployed on Tomcat to my domain - apache

I've installed Tomcat 9.0.27 on my Digital Ocean droplet running Ubuntu 18.04.3.
I deployed my Java WAR on Tomcat and am able to access it on the URL:
http://example.com:8080/app_name
I want to be able to directly access my WAR serving JSP through my domain.
So, when I hit example.com it directly serves my Java application.
I have tried several links to do the same. According to one of them (https://www.digitalocean.com/community/questions/how-to-tie-domain-name-with-application-running-on-tomcat), I did the following steps:
1. Enabled "proxy" and "proxy_http" using a2enmod
2. Restarted Apache2 service using systemctl restart
3. Created a new virtual host in a file named /etc/apache2/sites-available/tomcat.conf with the following contents:
<VirtualHost *:80>
ServerName www.example.com
ProxyRequests On
ProxyPass / http://localhost:8080/app_name/
ProxyPassReverse / http://localhost:8080/app_name/
</VirtualHost>
Enabled 'tomcat' site using a2ensite
Restarted Apache2 service using systemctl restart
Now when I hit example.com it does serve my homepage but all the CSS styles and images seem to be broken. The hyperlinks also don't work anymore.
My application is still being served at example.com:8080/app_name and on this URL everything works perfectly.
Please help me out with this.

Fixed this by renaming my webapp to "ROOT" and copying it to Tomcat.
Now the redirection is to http://localhost:8080.

Related

Laravel Valet with Apache + dnsmasq

I have Laravel Valet installed and configured to .loc domain (was working just fine)
Then I needed Apache server alongside with Laravel Valet, so I followed these instructions: https://getgrav.org/blog/macos-mojave-apache-mysql-vhost-apc
I configured Apache to serve .test domains. After I was done with instructions above, .test domains started working, but sites served by Laravel Valet (.loc) stopped working.
When I open any .loc site it loads localhost page (served by Apache).
My virtual hosts: /usr/local/etc/httpd/extra/httpd-vhosts.conf file:
<VirtualHost *:80>
DocumentRoot "/Users/daiyrbek/Sites"
ServerName localhost
</VirtualHost>
# and few other exact hosts like: site1.test -> ~/Sites/site1
What I want is:
.loc should be served by Laravel Valet
.test should be served by Apache
My /usr/local/etc/dnsmasq.conf file:
address=/.test/127.0.0.1
conf-file=/Users/daiyrbek/.config/valet/dnsmasq.conf
/Users/daiyrbek/.config/valet/dnsmasq.conf file:
address=/.loc/127.0.0.1
listen-address=127.0.0.1
How to work around this?
Basically it's not possible to achieve what I am trying to do as Laravel Valet's requirements are:
Valet requires macOS and Homebrew. Before installation, you should make sure that no other programs such as Apache or Nginx are binding to your local machine's port 80.
https://laravel.com/docs/6.x/valet#installation

Route 53 Sub Domain - EC2 Instance Issue

I am fairly new to AWS and have been trying to solve a problem. The problem statement; the company i work for currently have a cloud subscription with Atlassian for Jira and Confluence products. They want to move to a self-hosted license and so asked me to see what could be done.
I did the following steps:
Setup an Amazon Ec2 Instance
Associated an Elastic IP
In Route 53 I created a zone and did the necessary with Go Daddy to add name servers.
I installed Jira on the EC2 instance
I installed Confluence on the EC2 Instance
Now for the sake of this let's say my instance domain is ec2compute.amazonaws.com. Jira installed on port 8080 and confluence on 8090. If I navigate in my browser to ec2compute.amazonaws.com:8080 and ec2compute.amazonaws.com:8090 I get to the setup pages of Jira and Confluence.
So working as expected so far. Except I want to use my own domain - more importantly a sub-domain for Jira and a sub-domain for Confluence.
Going back to my domain, as I said i set the domain up lets say example.com in Route 53 and did the go daddy nameserver assignment. I installed apache on Ec2 and now if i go example.com i get the apache welcome page on my server...and if i go to example.com:8080 I get to the jira page and example.com:8090 i get to the confluence page.
What I want to do though is point jira.example.com to get to the jira page and confluence.example.com to get to the confluence page. I have tried updated the httpd.conf file with a virtual host for each but with no success.
Can someone please point me in the right direction ?
This should do (you can put it at the bottom of the httpd.conf or, even better, as separate .conf file in conf.d subfolder:
<VirtualHost *:80>
ServerName confluence.example.com
ProxyPreserveHost On
ProxyPass / http://localhost:8090/
ProxyPassReverse / http://localhost:8090/
</VirtualHost>
<VirtualHost *:80>
ServerName jira.example.com
ProxyPreserveHost On
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
</VirtualHost>
Use proxies when installing Confluence and Jira on the same server. To actually configure Confluence and Jira at separate urls, you'll also edit each app's server.xml (among other things). Atlassian has documents that instruct on Using Apache with mod_proxy and Proxying Atlassian server applications with Apache HTTP Server.

Wildfly, Tomcat, Apache and Subdomains

I have an Ubuntu server in AWS that is running multiple application servers -- a Wildfly serving up some pages and two Tomcats running a separate app.
I am trying to get subdomains working.
I have DNS's set up to point subdomain1.example.com, subdomain2.example.com. That works fine.
Wildfly is listening on port 80 (I think?), the Tomcats are listening on 8080 and 8090. The goal is to have www.example.com go to Wildfly, subdomain1.example.com go to Tomcat : 8080 and subdomain2.example.com go to Tomcat : 8090
I've found numerous posts that talk about setting up virtual hosts in Apache that should solve my problem. But I keep getting sent down rabbit holes. Some suggest adding to /opt/bitnami/apache2/bin/httpd.config and some suggest putting it in /opt/bitnami/apache2/sites-available/subdomain1.example.com.conf
My first issue: I don't think that Apache is even running. I was under the impression that Apache was baked into Wildfly, but when I execute:
service apache2 status
I get:
apache2.service
Loaded: not-found (Reason: No such file or directory)
Active: inactive (dead)
Running sudo service --status-all also doesn't show it running so I think that it is not. It seems to be installed (Bitnami stack) in /opt/bitnami/apache2
Do I have to turn Apache on as part of Wildfly (and how to turn it on)? If I do, then I would assume that Wildfly is no longer getting traffic.
Second - my research tells me I need i need to enable proxy and proxy_http using a2enmod and a2ensite but I don't have these. Research suggests that all Ubuntu's will have those scripts... do they get created if I turn on Apache?
Sorry for all the noob questions.... I'm a developer without a DevOps guy. This seems like it would so common it would be baked in or there would be a definite solution that I am probably missing.
For those looking for something similar, here is the solution that worked for me.
My server is a Wildfly-Apache2-MySQL AMI image on AWS. I did not need to use a2enmod nor a2ensite as my research suggested. It seems many of those modules are already enabled by the pre-built image.
NOTE THESE INSTRUCTIONS ARE BITNAMI AWI SPECIFIC - YOUR FLAVOR CONFIGURATION MAY BE SLIGHTLY DIFFERENT
To have a subdomain point to a simple Apache text site (yada.example.com):
Create a directory in ~/stack/apache2/htdocs called yada
Add an entry to the virtual hosts configuration file (sudo nano /opt/bitnami/apache2/conf/extra/httpd-vhosts.conf)
<VirtualHost *:80>
ServerAdmin info#example.com
DocumentRoot "/opt/bitnami/apache2/htdocs/yada"
ServerName yada.example.com
ErrorLog "logs/yada-subdomain-error-log"
CustomLog "logs/yada-subdomain-access-log" common
</VirtualHost>
Modify the Apache configuration file to include the virtual hosts. (sudo nano /opt/bitnami/apache2/conf/httpd.conf):
...snip...
# Supplemental configuration
#
# The configuration files in the conf/extra/ directory can be
# included to add extra features or to modify the default configuration of
# the server, or you may simply copy their contents here and change as
# necessary.
...snip...
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
# ADDED THE ABOVE LINE
...snip...
Restart Apache (sudo /opt/bitnami/ctlscript.sh restart apache)
To make it point to a Tomcat server, add this to the httpd-vhosts.conf:
<VirtualHost *:80>
ServerAdmin info#example.com
ServerName yada.example.com
ProxyPreserveHost On
# setup the proxy
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
ProxyPass / http://localhost:8090/
ProxyPassReverse / http://localhost:8090/
</VirtualHost>
Your port may differ.
FYI, I found this helpful: https://docs.bitnami.com/virtual-machine/components/apache/#how-to-configure-your-web-application-to-use-a-virtual-host
Good luck and shout out to #stdunbar for his guidance.

Apache httpd.conf - route request to different port

I have a CentOs 7.1 with Apache httpd running on port 9000.
So if i type in my browser: http://192.168.56.101:9000/ I see the Apache Testing 123 Page.
I also have a GitLab Server running on port 8888, but this port is closed by the firewall.
I want that Apache redirects traffic to http://192.168.56.101:9000/gitlab internally to the GitLab server.
I have done this in my Apache config file /etc/httpd/conf/httpd.conf:
<VirtualHost *:9000>
ProxyPass /gitlab http://192.168.56.101:8888/users/sign_in
ProxyPassReverse /gitlab http://192.168.56.101:8888/users/sign_in
</VirtualHost>
When users browse to http://192.168.56.101:9000/gitlab the login page appears (css seems broken though), but when logging in this appears:
Not Found
The requested URL /users/sign_in was not found on this server.
Is this something that is configurable with Apache and if so how?
Do I need to use some sort of Url-Rewriting, if yes which and how to get started?
All the links in gitlab will presume you are pointing at the original server.
So you need to look at mod_proxy_html to also replace these links in the HTML:
https://httpd.apache.org/docs/2.4/mod/mod_proxy_html.html

Apache and Cakephp application

I am running into issues with cakephp application running with CentOs. I did not change any setting in the default config other than added a file under conf.d which content as :
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /var/www/portal/
ServerName abc.mydomain.com
</VirtualHost>
When accessed, home page works i.e. app.mydomain.com shows up but none of the CSS,JS and img files are loaded which are under default structure
i.e. /var/www/portal/app/webroot/img
/var/www/portal/app/webroot/css
/var/www/portal/app/webroot/js
So I tried moving them right under /var/www/portal/ and that worked for homepage but clicking on any link on homepage just does 404. e.g. If link is abc.mydomain.com/test
In apache log I see the errors as 'File Does not exist : /var/www/portal/test' . It seems that apache is not sending the request to cakephp to process the url.
What could be wrong here? Most likely with the apache security settings but am not sure where to lool.
Is your AllowOverride set to all? Only then the CakePHP rewrite directives which are in .htaccess files start working. Alternatively, you can move them to the virtual host configuration and get them to work.
Ok, this is a common mistake. you should enable "rewrite" --> module rewrite. (this is of course a php module). in ubuntu you usually type sudo a2enmod rewrite. Check for CentOS command.