8

I am being having a lot of issues deploying my war file on my VPS.

I have java-8 and tomcat-8. My server is an Apache/2.2.22 (Debian) and my HTTP is on port 80 and tomcat on 8080.

Currently if you go to www.sdfasdfasdf.com you get an empty directory listed. However if you go to www.asdfasdf.com:8080/resumesite you get my page that is running on tomcat.

Naturally what I am trying to do is have the user input www.asdfasdffd.com and not the port etc.

So far I have set up a virtual host at nano /etc/apache2/sites-enabled/000-default.conf

<VirtualHost *:80>
    ServerAdmin fdfdf@asdfasdf.com

    ServerName www.sdfasdf.com
    ServerAlias asdfasdf.com

    ProxyPass /resumesite http://localhost:8080/resumesite
    ProxyPassReverse /resumesite http://localhost:8080/resumesite
</VirtualHost>

In my server.xml file in tomcat I set up a <Host></Host>

<Host name="www.asdfasdffasdf.com" appbase="webapps"
        unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">

        <Valve className="org.apache.catalina.valves.AccessLogValve"
                 directory="logs"  prefix="resumesite_log." suffix=".txt"
                 pattern="common"/>
      </Host>

With the above set up every single domain just lists my VPS's directory. At this point I do not know what to do.

My question is:

I want the user input www.asdfasdfasdf.com and not www.drew-jocham.com:8080/resumesite. I am attempting to do that, but like I said above, every single domain on my VPS just lists my servers whole directory with the above settings.

Also soon all the sites will be war files so there will be several domain names on the server. Some will be stored in tomcat webapps and some on my HTTP server on port 80 directly.

-------------------UPDATE 1-------------------

I went to nano /etc/apache2/sites-enabled/000-default.conf added the below and restarted my tomcat server.

<VirtualHost *:80>
    ServerAdmin fasdfad@asdfasdfasdf.com

    ServerName www.asdfasdfadf.com
    ServerAlias asdfasdfadf.com

    ProxyPass / http://localhost:8080/resumesite
    ProxyPassReverse / http://localhost:8080/resumesite
</VirtualHost>

When I go to www.asdfasdfasdf.com still nothing rendered besides the below picture:

enter image description here

Also it adds www.asdfasdf/resumesite to EVERY domain on my VPS in which I have several, thus breaking them all.

However if I still go to www.asdfasdfasdf.com:8080/resumesite it renders.

Mike3355
  • 11,305
  • 24
  • 96
  • 184
  • @SureshKoya sorry if I was not clear enough. Please read my last comment on my post. – Mike3355 Apr 29 '16 at 00:11
  • Just trying to unravel the mystery from the bottom up, here. What happens when you point your browser to http://www.drew-jocham.com:8080/resumesite? Does it just list the contents of the directory, as you're seeing when you're attempting to proxy? – Code4aliving May 03 '16 at 15:20
  • @BradBales No, it renders my page. – Mike3355 May 04 '16 at 12:59
  • If there are other sites on this VPS host and you have the configuration for drew-jocham.com in 000-default.conf file it could be a conflicting site configuration issues in apache. Have you tried running an apachectl configtest to identify any warnings or errors. Separating the site configs out is a best practice, and may help solve the issue. Are all the other VirtualHost configurations set up with a ServerName. – Sam May 06 '16 at 13:16
  • Using host based server names in Apache rather than IP based for your version of Apache 2.22 http://httpd.apache.org/docs/2.2/vhosts/name-based.html – Sam May 06 '16 at 13:24
  • @Sam I do not have any other `` set up. Currently /etc/apache2/sites-enabled/000-default.conf is empty. The other sites are on my htto server. This is my first time trying launch war file on a live server. – Mike3355 May 06 '16 at 19:20
  • @SureshKoya would you like to private chat? I really need to resolve this. – Mike3355 May 06 '16 at 22:46
  • @Drew1208, Sure we can do a private chat. I am available in US pacific time. – randominstanceOfLivingThing May 06 '16 at 22:57
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/111262/discussion-between-suresh-koya-and-drew1208). – randominstanceOfLivingThing May 06 '16 at 23:34

4 Answers4

4

I read your question as you want the root of www.drew-jocham.com to give you the content of the TomCat service http://localhost:8080/resumesite

<VirtualHost *:80>
    ServerAdmin drew@drew-jocham.com

    ServerName www.drew-jocham.com
    ServerAlias drew-jocham.com

    ProxyPass / http://localhost:8080/resumesite
    ProxyPassReverse / http://localhost:8080/resumesite
</VirtualHost>

This Digital Ocean guide on reverse proxying is a good read on the subject and includes many more Apache config items you might find useful (like SSL) - https://www.digitalocean.com/community/tutorials/how-to-use-apache-http-server-as-reverse-proxy-using-mod_proxy-extension

Sam
  • 602
  • 1
  • 6
  • 10
1

Step1:- Add the following configuration in tomcat8 server.xml

   <Host name="www.drew-jocham.com"  appBase="webapps"
        unpackWARs="true" autoDeploy="true">

  <Alias>www.drew-jocham.com</Alias>
    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
           prefix="$logprefix$." suffix=".txt"
           pattern="%h %l %u %t &quot;%r&quot; %s %b" />

   <Context path="" docBase="$RESUMESITEFOLDER$">
   <WatchedResource>WEB-INF/web.xml</WatchedResource>
    </Context>

    </Host>

In the apache create a site with following

<VirtualHost www.drew-jocham.com>
       ProxyPreserveHost On
       ServerName  www.drew-jocham.com
       ServerAlias www.drew-jocham.com
       Proxy Pass / http://localhost:8080/
       ProxyPassReverse / http://localhost:8080/
    </VirtualHost>

It above conf worked for my https://smartvocab.in

Abhinay
  • 464
  • 5
  • 13
1

You need several options in your apache enabled, such as vhost_alias, proxy_ajp and mod_jk I think. Also your tomcat needs ajp enabled. Add this to your apache config:

ServerName "yourdomain.com:80"
ServerAlias "www.yourdomain.com"
ServerAlias "ipv4.yourdomain.com"
UseCanonicalName Off

<IfModule mod_jk.c>
    JkMount /yourapp ajp13
    JkMount /yourapp/* ajp13
    JkMount / ajp13
    JkMount /* ajp13
</IfModule>
John Smith
  • 173
  • 3
  • 13
0

You need to follow these steps:

Step 1: Before configuring Apache, you should enable the necessary modules.

a2enmod proxy
a2enmod proxy_http

Step 2: Next, you are going to modify the default configuration file 000-default.conf inside /etc/apache2/sites-enabled to set up "proxying" functionality.

<VirtualHost *:*>
    ProxyPreserveHost On
    ProxyPass / http://0.0.0.0:8080/
    ProxyPassReverse / http://0.0.0.0:8080/
    ServerName localhost
</VirtualHost>

Step 3: Next, you are going to modify the server.xml file.

<Host name="www.drew-jocham.com" appbase="webapps"
        unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">

        <Valve className="org.apache.catalina.valves.AccessLogValve"
                 directory="logs"  prefix="resumesite_log." suffix=".txt"
                 pattern="common"/>
        <Context path="" docBase="/resumeSite" debug="0" reloadable="true"/>

</Host>

Once you are done with your configuration, you will need to restart the cloud server for the changes to go into effect. Execute the following command to restart Apache: service apache2 restart

And that’s it!

Read more: https://medium.com/@ldclakmal/deploy-a-java-web-application-in-digitalocean-882226dcdbd5

Chanaka Lakmal
  • 1,112
  • 9
  • 19
  • 1
    This works after you set `resumesite` as your tomcat's root by modifying `opt/tomcat/conf/server.xml` – S.Dan Apr 16 '17 at 12:46