• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Setup subdomain in Windows Tomcat 8

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all
I have a windows VPS with installed tomcat 8.0. I've changed default 8080 port to 80 and now, and i've also added a subdomain "s1.example.com" to my SHARED host via cpanel, pointing that to IP of VPS server.
Everything works right up to this point. I can put my (HTML) files in ROOT folder of tomcat and see them in address s1.example.com.
Now, I want to map another subdomain "s2.example.com" to a subfolder ROOT/folder1. I'm confused how to do that. All internet tutorials are linux-based and i can't understand them.
I've checked adding following code to server.XML, but no help.



Hint: I'm using tomcat because i have java war loaded for s1.example.com. Now, i'm gonna use s2.example.com as a download server which serves my files.
Regards
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Al!

Tomcat is not a file server. You don't "copy files to/from directories", you create and deploy J2EE WARs to it. The ROOT folder as it comes from the Tomcat website contains a WAR that's bound to the webapp context path "/". That WAR is in "exploded" (unzipped form). Other WARs are conventionally resident in directories under TOMCAT_HOME/webapps where the directory name determines the context path that that particular WAR is served under.

You are not actually working with a subdomain here, you're dealing with Virtual Hosts. In a fully-qualified Domain Name (FQDN) the top level (first element) of the domain name is the hostname.

In the stock Tomcat, there's only one virtual host, known by its alias name of "localhost" and its default appBase directory is "webapps". Or more precisely, %CATALINA_BASE%/webapps. So the only thing wrong with your Host stanza is that you are trying to embed one appBase directory under another appBase directory. You need them on separate directory paths.
 
Al Alavi
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your help
And sorry if i'm a newbie.
I couldn't get what you mean correctly.
Do you mean placing HTML-JS-CSS files in ROOT folder is logically wrong? (in HTML, i call another WAR file - which has already been deployed to Tomcat via its interface.)

So, for s2.exmaple.com, what is the best way to server files. Am i in the right way for using tomcat (while port 80 has already been occupied by tomcat) or i should use Apache or IIS or so? (Or maybe its also better to move those Html files from s1.example.com to Apache/IIS)

Best Regards
 
Tim Holloway
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, "Placing files" is wrong. Tomcat is not a file server, it is a web server. Web Servers return content based on incoming URLs over network links. File servers operate via OS Open/close/create/update/delete calls. The mechanisms are very, very different.

The confusion comes from 2 sources:

1. The default action for a webapp server to resolve a URL if no explicit resolution mechanism is targeted is for the webapp server to search the web application and locate a resource whose application pathname corresponds to the unresolved part of the URL. This resource - if located - is then opened locally by the webapp server and its contents are copied out to the HTTP response stream.

2. The syntax of a URL looks a lot like Unix-style filename paths. Since the default behavior described above also looks like a filesystem operation, people think that the webapp server is serving files. But it's an illusion, not reality.

As I said before, "placing files" doesn't work. You have to have an actual WAR (either a ".war" file or the equivalent as a set of directories). That includes a WEB-INF directory and usually a /WEB-INF/web.xml file. When you downloaded Tomcat, a WAR already existed in the TOMCAT_HOME/webapps/ROOT directory. If you just dump files randomly in on top of it, you'll just end up with a damaged webapp and it won't do what you expect it to.

You can remove the original ROOT directory and replace it with another one with a webapp of your own design, but it has to be a valid WAR format.

Every webapp in a Tomcat server is completely distinct and self-contained. You cannot share files between webapps or Virtual Hosts unless they are stored in some location external to Tomcat and the appBase directories. And if you do, you have to provide the code that retrieves and transmits their contents - Tomcat will not do that for you.

Finally, if all you want to do is serve static content, yes, a simple webserver like Apache HTTPD or IIS is sufficient.
 
Al Alavi
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Tim. It was so informative. It drived me to read more about Tomcat.

some points:
1. By saying download server or file server, i meant a server which serves my static contents. Of course, my static content for s2.example.com are just some RAR/ZIP files that user downloads them from web. (In fact, in my shared host (example.com) i have wordpress which lets users download some contents. Because of heavy load on my shared host from downloadable contents, I decided to transfer those files into another server and subdomain s2.example.com)

2. As i understood, both Apache and Apache Tomcat- or shortly Tomcat- are web servers and when we say Web Server, It means they can handle HTTP request. (Today, users download from internet via HTTP protocol. isn't it?). But the difference is that "just placing files" in Apache is enough and in Tomcat it requires more than "just placing files". Tomcat may requires some programming or configuration. Am i right? (so what i have done for s1.example.com - i.e. removing all files in ROOT folder and placing my HTML files- has been wrong.)

3. To clarify more, Now i have installed GeoServer (which is WAR file) on Tomcat and i need GeoServer. I have also some HTML files which uses Geoserver to display maps in s1.example.com.
I'm still confused. Is it better to change port on Tomcat back to 8080 and install Apache beside it and let Apache handle both content on s1.example.com and s2.example.com?

Regards
 
Lookout! Runaway whale! Hide behind this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic