How to serve static files from Apache Server (not from Tomcat) - apache

I am running my Web application project using Tomcat alone. Now I would like to improve my site performance using Apache altogether with Tomcat. And static contents like css, images, js have to be served from Apache not form Tomcat.
I have heard like Apache httpd and Ant build files has to modified to meet out my requirement.
Can anyone suggest what should be done?
Thanks in advance!!!

Related

Correct Apache Configuration And Htaccess

I've just reset my Ubuntu 14.04 LAMP server hosted with digital ocean. Could someone tell me the 'proper' way to do server configuration. My goal is to do everything as clean as possible (and hopefully well structured).
I intend on using the server mainly for programming and data analytics, however I do plan on hosting my website in /var/www/html. I also plan on using letsencrypt/certbot to get an easy SSL. With this in mind, these are the main goals I would like to accomplish:
1) Redirect the website to ALWAYS be served through https AND www.
2) Enable HSTS for the entire website.
3) Enable clean url's (remove .php extensions and what not).
Since I would like all of these properties to be used across the entire website, should the configuration be done inside of the /etc/apache2/ folder? Or should it be done inside of .htaccess?
And if it should be done inside of apache2 configuration, which file should I add it to? And finally, how exactly should it be added? (for example vhost 80/443, inside of a mod_something section, etc).
Thank you in advance, I would appreciate and consider any advice about Apache and htaccess!

JSP file is served as plain/text, when TOMCAT is behind an APACHE server

I'm running in a strange problem. I have a project based on MAVEN. When I run the project directly from my computer for testing it, using mvn tomcat7:run, my website display is correct. When I upload it to my distant Tomcat server, that is accessed through the JK Apache Tomcat connector, the JSP page is served as a text file. In response headers, I can see Content-Type:text/plainwhich is almost strange, and I'm suspecting the Apache server is adding it because of some erroneous configuration.
Any idea where to look, to fix this problem ?

Static file location and cache control headers

When using the basic Tomcat container in Cloudbees, are the static files served by Tomcat or Apache? I need to set the header so browsers do not cache a certain file which would be done in the Apache .htaccess file or I could write a servlet filter for Tomcat to do the same thing.
Cloudbees don't use Apache frontend but nginx. All requests, including static resources, are served by the application container (tomcat, jboss). A best practice is to distribute them on a CDN for better performances and low latency for application users, see http://wiki.cloudbees.com/bin/view/RUN/Using+a+CDN
In my experience all requests arrive at the Tomcat level.
Here is an exempt from my service logs at cloudbees:
11:10:53.031 [http-8841-2] DEBUG o.s.w.s.DispatcherServlet - DispatcherServlet with name 'spring' processing GET request for [/resources/images/logo.png]
Obviously the request for the logo.png file got there.
By the way, I think they use ngineX not Apache.

serve a GWT application from the app server root

I have a GWT application, which I deploy as a WAR file to a Jetty 8 server.
I want it to be accessible via
http://<myserver>/
instead of
http://<myserver>:8080/MyApp/MyApp.html
I understand I can configure Jetty to run on port 80 instead of 8080 or have an apache instance running on port 80 and forwarding requests to Jetty running on 8080 (don't see a benefit of the latter, though).
but how can I deploy the GWT app to be accessible at the server ROOT?
so far I see I can create myapp.xml in Jetty/contexts folder and put
<Set name="contextPath">/</Set>
there. I can also rename MyApp.html to index.html. but I'm not sure this is the "recommended" approach
I think you pretty much answered your own question:
The application server (e.g. Jetty) is responsible for the context path, so you must set it somehow in the application server. This is different for each server, e.g. in Tomcat one possibility to achieve this is renaming the war file to ROOT.war. (I don't know all the possible ways how to do this in Jetty off-hand.)
Note: The file that is served when going directly to the context URL can be determined in your web.xml, using
<welcome-file-list>
<welcome-file>MyApp.html</welcome-file>
</welcome-file-list>
So you don't have to rename it to index.html.
ok, accepting my own answer:
create myapp.xml in Jetty/contexts folder
thank you, Chris!

Is it possible to use apache tomcat server as a http file server >

I have installed apache tomcat server on my machine for hosting some servlets. Now I want to put some files on this server so that user can download these files straight away. My question is is it possible to do this ? I mean can apache tomcat server act as a http server as well ? If yes, in which directory in tomcat server I should put these files ?
Please help,
Several pointers (from Google):
http://denis-zhdanov.blogspot.com/2009/08/configure-tomcat-static-content.html
Stackoverflow: How to serve static content from tomcat
Enable the file listing in conf/web.xml and then delete all the files in webapps/root directory and replace it with the files you want to transfer.
The below link could be helpful
https://www.youtube.com/watch?v=pJPOBKLYZYY