Deploying routed angular 5 application on tomcat 7 for routing work correctly - tomcat7

For using tomcat 7 to be deployment server for routed angular application the server needs some settings to be fallback on index.html for routing to be work from the browser's url box. refer to angular.io
What configuration do I need in tomcat 7 in order to achieve this?

In case you still need it:
You need to add the rewrite Valve to your tomcat server.xml file (~/conf/server.xml), like this:
<Host name="localhost" appBase="webapps"unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.rewrite.RewriteValve" />
...
</Host>
Also, you need to write rewrite rule in rewrite.config:
Create rewrite.config file in ~/conf/Catalina/localhost/ with the following content:
RewriteCond %{REQUEST_PATH} !-f
RewriteRule ^/appName/(.*) /appName/index.html
And change the baseHref for your app to serve files and route correct for deep links. this is an example:
ng build --prod --baseHref=http://hostname:port/appName/
This is working for me in tomcat 8.xx and 9.x.x

Related

Laravel 8 project deploy to shared hosting - security issues and public_html folder

I was able to deploy my laravel 8 application as and addon domain on inmotion shared hosting based on the following article
https://medium.com/backenders-club/how-to-host-a-laravel-project-on-a-shared-hosting-via-cpanel-d955d32c528e
However, there are security issues with this as I can type mysite.com/.env and the file contents is listed in the browser showing the passwords.
I've tried many options to place the public folder of my laravel app into a public_html/public folder and none have worked for me. Anyone also getting this problem?
Addon domain Document root - /public_html/public
Laravel 8 application - /mysite.com (public folder contents moved to public_html/public)
Inside the public_html/public folder, the index.php file modified as follows:
require __DIR__.'/../../mysite.com/vendor/autoload.php';
$app = require_once __DIR__.'/../../mysite.com/bootstrap/app.php';
In browser I get 'No input file specified.'
bad practice if you try to move files inside public folder to root directory , any one can view the files that exist in the root ,
my advice to you ,return your files to the public folder and use one solution from this :-
first , you can make change the domain document root to public path
second you can create .htaccess file in the root folder and contain this code :-
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
i prefer the first solution.

How do I set default page for my website if the index file is located inside a couple of more folders in htdocs?

When I load my website I want the default page to be loaded but it is located inside two more folders in htdocs. I tried changing .htaccess but it did not work as I expected. This is my directory structure:
htdocs\hotel-management-repo\hotel-app\index.php
What rule did you apply in the .htaccess? Have you tried something like:
RewriteRule ^index.php$ hotel-management-repo\hotel-app\index.php [QSA,L]

Setting context name in thymeleaf with spring boot deployed on tomcat8 behind apache reverse proxy

I am trying to :
setup a sub domain, in which root path / will proxy local tomcat's running thymeleaf + spring boot app at http://localhost:8080/myuiapp/,
With a flexibility that I can change the context path to /application or /demo or /anything in future (with just apache config changes) without any codebase or tomcat config changes.
The problem I'm facing is:- thymeleaf is not changing context name when deployed on standalone tomcat8. (I got to know that context path property affect only in embedded tomcat server)
So th:href="#{/assets/vendors/global/vendors.bundle.css}" is computed as href=/myuiapp/assets/vendors/global/vendors.bundle.css always.
Here's one of the virtual host config that I've tried:
<VirtualHost _default_:443>
ServerName foo.domain.com
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/foo.domain.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/foo.domain.com/privkey.pem
ProxyPreserveHost On
ProxyPass / http://localhost:8080/myuiapp/
ProxyPassReverse / http://localhost:8080/myuiapp/
ProxyPass /newapp/ http://localhost:8080/myuiapp/
ProxyPassReverse /newapp/ http://localhost:8080/myuiapp/
</VirtualHost>
I have tried the following things:
1) Apache sending headers to application and application respecting those headers
SSLProxyEngine on
ProxyPreserveHost on
RequestHeader set X-Forwarded-Proto https
RequestHeader set X-Forwarded-Port 443
server.use-forward-headers=true
2) Setting context path manually
System.setProperty("server.servlet.context-path", contextPath)
3) Server-relative URLs in Thymeleaf - link (It solves my first problem of Root / context path but not /any context path)
<a th:href="#{~/billing-app/showDetails.htm}">
Need your help in setting dynamic context-name, when we deploy on standalone tomcat which is recognised by thymeleaf as well.
I had a similar issue. I had the following line in the html file
<link rel="stylesheet" th:href="#{/css/stylesheet.css}"/>
and the stylesheet was found at http://localhost:8321/css/disclaimer.css and correctly applied (notice the lack of application name on the path).
However on production the new link to the css was https://example.com/app-name/css/stylesheet.css
but in the html it was still pointing wrongly to https://example.com/css/stylesheet.css
To fix this I had to remove the initial / from href like so:
<link rel="stylesheet" th:href="#{css/stylesheet.css}"/>
and the css applied both locally and in production.
I stood at the same question and I solved the problem with thymeleaf and javascript as following.
Lets say my context-path is /app/
In Thymeleaf you can get it via:
<script th:inline="javascript">
/*<![CDATA[*/
let contextPath = /*[[#{/}]]*/
/*]]>*/
</script>

Reverse proxy with Apache and static content behind application inside of jetty

My applications is spring based and served by jetty. The current setup looks like this.
Apache - > Reverse proxy -> Embedded Jetty -> Application
When I access the app directly (http://127.0.0.1:15000) without reverse proxy the static resources are loaded (css, .js etc) but if I access it through reverse proxy
(https://127.0.0.1/app/) it doesn't work.
Here are my configs.
apache2.conf
ProxyPass /app/ http://127.0.0.1:15000/
ProxyPassReverse /app/ http://127.0.0.1:15000/
SSLProxyEngine on
RewriteEngine On
RewriteRule /app$ /app/ [R]
spring-servlet.xml
...
<mvc:default-servlet-handler />
<mvc:resources mapping="/resources/**" location="/resources/" />
...
I would like that in both ways the static content will be delivered.
I know this is too late. But for anyone who might end up here, Adding a mapping to your resources path will solve the problem.
ProxyPass /app/resources http://127.0.0.1:15000/app/resources
ProxyPassReverse /app/resources http://127.0.0.1:15000/app/resources
This should be added before your existing mapping.(longest URL comes first, as whichever mapping is read first, wins)

url rewrite debian

I just got fresh debian VPS into my hands.
I installed url rewrite and simple things like this does seem to work
RewriteRule ^login$ /login.php
However this doesn't work:
RewriteRule ^cats$ /index.php?cat=cats
Anyone have idea why?
(it works on local xampp server + it worked on shared host I had)
Thanks
First of all make sure that you have mod_rewrite, and it's on. To do so, create an empty Php file, then add <? phpinfo() ?> and diplay it in your browser.
If it's "on" then you can go on.
If it's in a .htaccess file then try with / without the slashes.
RewriteRule ^cats$ /index.php?cat=cats
Or
RewriteRule ^/cats$ /index.php?cat=cats
And if that's not enough:
Two hints:
If you're not in a hosted environment (= if it's your own server and you can modify the virtual hosts, not only the .htaccess files), try to use the RewriteLog directive: it helps you to track down such problems:
# Trace:
# (!) file gets big quickly, remove in prod environments:
RewriteLog "/web/logs/mywebsite.rewrite.log"
RewriteLogLevel 9
RewriteEngine On
My favorite tool to check for regexp:
http://www.quanetic.com/Regex (don't forget to choose ereg(POSIX) instead of preg(PCRE)!)

Resources