Strato V-Server "de-domain" umleiten

stefan2902

New Member
Tomcat Apache2 mod_jk virtueller Host

Hallo,

auch ich bin neu in der Serveradministration und habe ich eine Frage.

Hintergrund

Ich habe einen V-Server von Strato wie folgt eingerichtet, da ich WebApps mit Java deployen und auf einzelne "de-domainen" umleiten möchte:

- Ubuntu 10.04
- Apache2
- Tomcat7
- mod_jk
- MySql
- PHPMYAdmin

Das scheint auch alles gut prima zu funktionieren. Apache2 hört auf Port 80, Tomcat7 hört auf Port 8080.

Mein Problem oder eher Frage lautet:

Ich habe eine weitere "de-domäne" registriert und möchte diese auf eine WebApp aus dem Tomcat Verzeichnis umleiten. Sowas wie:

www.meinedomaene.de auf /usr/share/tomcat7/webapps/meineapp.

Ich habe im Internet ein wenig referchiert und denke ich muss VirtualHosts einrichten?! Ich habe das von folgender Seite: http://diegobenna.blogspot.de/2011/01/connect-tomcat-7-with-apache2-modjk-and.html

Da ich jedoch nicht meine ganze Installation gefähren möchte, habe ich mich gefragt, ob mir jemand sagen kann, was ich im Minimum tun muss, um das zu erreichen? Muss ich z.B. auch meine /etc/hosts anpassen? Wäre toll, wenn mir jemand damit weiterhelfen könnte.

Gruß

Stefan
 
Last edited by a moderator:
Wenn die Domain sauber auf die IP deines Servers zeigt, VirtualHost im Apache einrichten. Sonst nix.

Grundsätzlich: Ein eigener Server ist nicht zum Lernen da. Das sollte man vorher erledigt haben.
 
Vielen Dank für die schnelle Antwort.

Ich habe nun folgende Änderungen vorgenommen:

1. In Datei /etc/apache2/ports.conf habe ich folgende Zeile hinzugefügt:

NameVirtualHost *:8080

2. Neue Datei angelegt names /etc/apache2/sites-available/domain.tld

Code:
<VirtualHost *:8080>
        ServerName domain.tld
        ServerAdmin webmaster@localhost
        DocumentRoot /usr/share/tomcat7/webapps/examples/
        <Directory  /usr/share/tomcat7/webapps/examples/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>
        ErrorLog /var/log/apache2/error.log
        LogLevel warn
        CustomLog /var/log/apache2/access.log combined
        ServerSignature On
</VirtualHost>

3. Activate site and restart apache 2:

Code:
sudo a2ensite domain.tld
sudo /etc/init.d/apache2 reload
sudo /etc/init.d/apache2 restart

Das führt nun dazu, dass ich die Seite /usr/share/tomcat7/webapps/examples/ angezeigt bekomme, sobald ich domain.tld aufrufe.

Muss ich eine besondere Directive im VirtualHost beachten, wenn ich Servlets ausführen möchte?

Nochmals danke für die Hilfe.

Gruß
Stefan
 
Hallo,

Da ich mein Problem noch nicht ganz gelöst habe, würde ich gerne mal meine Config Files mit Euch teilen. Vielleicht fällt dem einen oder anderen ja auf, was mir fehlen könnte. Ich habe mir bereits die offizielle Doku und zahlreiche Tutorials angesehen aber irgendwie scheine ich nicht den Fehler zu finden.

Mein Problem: Ich bin immer noch nicht in der Lage mittels vHosts ein Java Servlet (unter /usr/share/tomcat7/webapps/bundesliga) auf meine Domäne walsumerjungs.de zu mappen.

Proxy.conf

Code:
<IfModule mod_proxy.c>
#turning ProxyRequests on and allowing proxying from all may allow
#spammers to use your proxy to send email.

ProxyRequests Off

<Proxy *>
AddDefaultCharset off
Order deny,allow
Allow from all
#Deny from all
#Allow from .example.com
</Proxy>

# Enable/disable the handling of HTTP/1.1 "Via:" headers.
# ("Full" adds the server version; "Block" removes all outgoing Via: headers)
# Set to one of: Off | On | Full | Block

ProxyVia On
</IfModule>

Ports.conf
Code:
NameVirtualHost *:80
Listen 80

<IfModule mod_ssl.c>
    Listen 443
</IfModule>

<IfModule mod_gnutls.c>
    Listen 443
</IfModule>

server.xml

Code:
<?xml version="1.0" encoding="UTF-8"?>
  <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine=
"on" />
  <Listener className="org.apache.catalina.core.JasperListener" />
  <!-- Prevent memory leaks due to use of particular java/javax APIs-->
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"
 />
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListen
er" />
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListene
r" />

  <GlobalNamingResources>
    <Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
              description="User database that can be updated and saved"
              factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
              pathname="conf/tomcat-users.xml" />
  </GlobalNamingResources>

  <Service name="Catalina">

    <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
               maxThreads="150" scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS" />

    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
    <Engine name="Catalina" defaultHost="localhost">

      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>
      </Realm>

      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">

        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log." suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />

        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log." suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />

      </Host>
	<Host name="walsumerjungs.de" appBase="webapps"
	unpackWARs="true" autoDeploy="true"
	xmlValidation="true" xmlNamespaceAware="false">
	<Context path="/bundesliga" docBase="ROOT" reloadable="true" privileged="true" antiResourceLocking="fal
	se" anitJARLocking="false">
	</Context>
	</Host>
    </Engine>
  </Service>
</Server>

/etc/apache2/sites-available/walsumerjungs.de

Code:
<VirtualHost *:80>
ServerName www.walsumerjungs.de
JKMount /bundesliga/* worker
JKMount /bundesliga worker
  RewriteRule ^/$ / [R=permanent]
  RewriteRule ^/(.*)$ ajp://localhost:8009/$1 [P]
  RewriteEngine on
</VirtualHost>


http.conf

Code:
ServerAdmin webmaster@localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory /usr/lib/cgi-bin>
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>

ErrorLog /var/log/apache2/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog /var/log/apache2/access.log combined

Alias /doc/ /usr/share/doc/
<Directory /usr/share/doc/>
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>

error.log
Code:
b7f07000-b7f09000 rw-p b7f07000 00:00 0
b7f09000-b7f24000 r-xp 00000000 00:20 1337521                            /lib/ld-2.11.1.so
b7f24000-b7f25000 r--p 0001a000 00:20 1337521                            /lib/ld-2.11.1.so
b7f25000-b7f26000 rw-p 0001b000 00:20 1337521                            /lib/ld-2.11.1.so
b7f26000-b7f84000 r-xp 00000000 00:20 1442957                            /usr/lib/apache2/mpm-prefork/a          pache2
b7f84000-b7f86000 r--p 0005d000 00:20 1442957                            /usr/lib/apache2/mpm-prefork/a          pache2
b7f86000-b7f88000 rw-p 0005f000 00:20 1442957                            /usr/lib/apache2/mpm-prefork/a          pache2
b7f88000-b7f8b000 rw-p b7f88000 00:00 0
b9bde000-b9f53000 rw-p b9bde000 00:00 0                                  [heap]
bffdd000-bfff2000 rw-p 7ffffffe9000 00:00 0                              [stack]
[Mon Oct 01 16:05:45 2012] [notice] caught SIGTERM, shutting down
PHP Deprecated:  Comments starting with '#' are deprecated in /etc/php5/apache2/conf.d/mcrypt.ini on li          ne 1 in Unknown on line 0
[Mon Oct 01 16:05:46 2012] [notice] Apache/2.2.14 (Ubuntu) mod_jk/1.2.28 PHP/5.3.2-1ubuntu4.18 with Suh          osin-Patch configured -- resuming normal operations
[Mon Oct 01 16:05:48 2012] [error] (111)Connection refused: proxy: AJP: attempt to connect to 127.0.0.1          :8009 (*) failed
[Mon Oct 01 16:05:48 2012] [error] proxy: AJP: failed to make connection to backend: localhost

Falls Ihr irgendwelche Ideen, Anregegungen hättet, wäre ich sehr dankbar.

Bitte lasst mich auch wissen, falls Ihr noch ein Info braucht.

Gruß
Stefan
 
Hallo,

Zunächst mal Sorry, dass ich hier noch mal selber poste, aber - nachdem ich nun die Config und Error Files gepostet habe - denke ich, dass ich noch nicht verstanden habe, an welcher Stelle ich die Verzeichnisstruktur der Servletlocation angeben muss. Woher soll Apache wissen, dass das Servlet unter .../bundesliga/tippspiel liegt?!

Ich denke, dass es daran bei mir scheitert.

Gruß
Stefan
 
Sowohl die Fehlermeldung als auch Deine Config-Angaben lassen mich vermuten, dass mod_jk noch nicht korrekt eingebunden ist. Entweder bin ich Blindfisch oder mir fehlt sowas z.B. hier:

/etc/apache2/workers.properties
Code:
workers.tomcat_home=/usr/lib/apache-tomcat
workers.java_home=/usr/lib/jdk
ps=/
worker.list=worker1
worker.default.port=8009
worker.default.host=localhost
worker.default.type=ajp13
worker.default.lbfactor=1

/etc/apache2/apache2.conf
Code:
LoadModule jk_module /usr/lib/apache2/modules/mod_jk.so
# Where to find workers.properties
JkWorkersFile /etc/apache2/workers.properties
# Where to put jk 
logsJkLogFile /var/log/apache2/mod_jk.log
# Set the jk log level
[debug/error/info]JkLogLevel info
# Select the log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
# JkOptions indicate to send SSL KEY SIZE,
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
# JkRequestLogFormat set the request format
JkRequestLogFormat "%w %V %T"

P.S.: und ändere mal den Thread-Titel ab, dass hier hat nix mit VServer, Strato oder Domain zu tun sondern mit Tomcat und Virtualhosts.

P.S.S.: Wenn Du PHP nur wegen PHPMyAdmin brauchst, schau Dir mal http://code.google.com/p/jsp-myadmin/ an. Mglw. Lässt sich das Apache-Zeugs dann ganz einsparen in Deinem Fall, denn da scheint es mir nicht auf Hochperformance anzukommen.
 
Last edited by a moderator:
Vielen Dank für deine Antwort. Diese Configs habe ich auch gesetzt; jedoch vergessen zu posten. Hier meine Inhalte

/etc/apache2/workers.properties

Code:
# Define 1 real worker using ajp13
worker.list=worker
# Set properties for worker (ajp13)
worker.worker.type=ajp13
worker.worker.host=localhost
worker.worker.port=8009

/etc/apache2/mods-available/jk.load

Code:
LoadModule jk_module /usr/lib/apache2/modules/mod_jk.so
# Where to find workers.properties
# Update this path to match your conf directory location (put workers.properties next to httpd.conf)
JkWorkersFile /etc/apache2/workers.properties
# Where to put jk shared memory
# Update this path to match your local state directory or logs directory
JkShmFile     /var/log/apache2/mod_jk.shm
# Where to put jk logs
# Update this path to match your logs directory location (put mod_jk.log next to access_log)
JkLogFile     /var/log/apache2/mod_jk.log
# Set the jk log level [debug/error/info]
JkLogLevel    info
# Select the timestamp log format JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "

Ich befürchte, dass der der virtuelle Host nicht weiß, dass das Servlet unter www.domain.de:8080/bundesliga/tippspiel zu finden ist?
 
Hallo,

Ich habe nun Fortschritte gemacht.

Die Einrichtung von mod_jk scheint nun zu funktionieren, da ich auf beiden Ports (80 und 8080) nun mein Servlet angezeigt bekomme:

http://hxxxxxx.stratoserver.net:8080/bundesliga/tippspiel

http://hxxxxxx.stratoserver.net/bundesliga/tippspiel

Da zeigt doch schon mal, dass die Einrichtung von mod_jk zu funktionieren scheint.

Was noch nicht klappt, ist, dass http://www.walsumerjungs.de nun auf dieses Servlet verweist.

Meine Minimalkonfiguration für die virtual Host Datei lautet:

Code:
<VirtualHost *:80>
ServerName www.walsumerjungs.de
JkMount /* worker
</VirtualHost>

Der relevante Block aus der server.xml Datei lautet (Hinweis: appBase ist eingerichtet):

Code:
        <Host   name="walsumerjungs.de" 
                appBase="/var/www/walsumerjungs.de/webapps" 
                unpackWARs="true">
        <Context path="" docBase="/bundesliga" debug="0"/>
        <Alias>www.walsumerjungs.de</Alias>
        </Host>

Meine web.xml Datei des Servlet's zeigt auf:

Code:
  <servlet>
    <servlet-name>bundesliga</servlet-name>
    <servlet-class>de.stefan.tippspiel.Controller</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>bundesliga</servlet-name>
    <url-pattern>/tippspiel</url-pattern>
  </servlet-mapping>

Ich denke nicht, dass noch viel fehlt. Hat jemand noch einen Tipp für mich???

Vielen Grüße und schönes Wochenende.

Stefan
 
Last edited by a moderator:
Back
Top