Portál AbcLinuxu, 10. května 2025 09:31
Dobry den. Uz nekolik dni se snazim rozbehat Tomcat v soucinnosti s apachem. Apach by mel fungovat standardne na portu 80 a zpracovavat pouze staticky obsah. Oproti tomu by pozadavky na zpracovani stranek *.jsp mel smerovat na Tomcat. Tomcat pouzivam posledni verze. Provedl jsem konfiguraci presne podle dokumentace, ale stale se mi nedari rozbehat potrebnou aplikaci. Kupodivu je ale funkcni napriklad zadani http://localhost/examples/jsp/security/index.jsp. Apache preda pozadavek na Tomcat a ten jej interpretuje. Ale aplikace http://localhost/kramerius nefunguje. Pritom se nachazi ve stejne slozce webapps. Prohlizec vyhodi chybu 403. V logu error_log Apache je zaznam: [Thu Mar 12 11:54:52 2009] [error] [client 127.0.0.1] client denied by server configuration: /srv/tomcat6/webapps/kramerius. Log mod_jk je cisty (pouze je uvedeno, ze byla knihovna uspesne inicializovana). Logy Tomcatu jsou taktez bez chyb.
Pro predstavu o konfiguraci zde uvadim obsah nekolika souboru.
mod_jk.conf:
# Load mod_jk module
LoadModule jk_module /usr/lib/apache2/mod_jk.so
# Where to find workers.properties
JkWorkersFile /usr/share/tomcat6/conf/jk/workers.properties
# Where to put jk logs
JkLogFile /var/log/apache2/mod_jk.log
# Set the jk log level [debug/error/info]
JkLogLevel info
#JkShm:
JkShmFile /var/cache/tomcat6/temp/jkshm.file
<VirtualHost *:80>
ServerName localhost
#DocumentRoot /srv/www/htdocs
#################### xxx.yyy.com:/kramerius ####################
# Static files
Alias /kramerius "/srv/tomcat6/webapps/kramerius"
<Directory "/srv/tomcat6/webapps/kramerius">
Options Indexes FollowSymLinks
DirectoryIndex index.html index.htm index.jsp
</Directory>
# Deny direct access to WEB-INF and META-INF
#
#<Location "/kramerius/WEB-INF/*">
#AllowOverride None
#deny from all
#</Location>
#<Location "/kramerius/META-INF/*">
#AllowOverride None
#deny from all
#</Location>
JkMount /*.jsp worker1
JkMount /kramerius/*.jsp worker1
###############################################################
</VirtualHost>
Do hlavniho konfiguraku httpd.conf servru apache jsem pouze na konec pridal:
Include /usr/share/tomcat6/conf/jk/mod_jk.conf-auto
Do souboru server.xml Tomcatu jsem pridal:
<Listener className="org.apache.jk.config.ApacheConfig" modJk="/usr/lib/apache2/mod_jk.so" />
a to za posledni direktivu </Hos> a pred direktivu </Engine> v souboru.
Pro prehled stavu sitovych sluzeb jeste uvadim vypis prikazu nmap localhost:
PORT STATE SERVICE
22/tcp open ssh
25/tcp open smtp
80/tcp open http (apache)
111/tcp open rpcbind
631/tcp open ipp
5432/tcp open postgresql
8009/tcp open ajp13 (rozhrani apache-tomcat)
8080/tcp open http-proxy
8081/tcp open blackice-icecap (tomcat)
8082/tcp open blackice-alerts (tomcat)
Protoze uz si s tim hraji púar dnu a netusim v cem by skrze logy mohla byt chyba, zkousim stesti tady a doufam, ze se zde nekdo, kdo se vyzna v technologii JSP a virtualhostingu s apachem.
JEste jsem zapomel na soubor worker.properties, ktery se nachazi ve stejnem umisteni, jako mod_jk.conf:
worker.list=worker1
worker.worker1.port=8009
worker.worker1.host=localhost
worker.worker1.type=ajp13
Ted uz by snad konfigurace mela byt uplna.
Primo s tvym dotazem ti neporadim. Chvili jsem si s Tomcatem hral, ale nepodarilo se mi take u nej nastavit tehdy co jsem potreboval. Takze jsem sahnul jinam.
http://java.sun.com/javaee/downloads/index.jsp
https://glassfish.dev.java.net/
a jsem plne spokojenej.
Ale aplikace http://localhost/kramerius nefunguje.V konfiguraci máte nastaveno, aby Tomcatu přeposílal jen požadavky na
*.jsp
. Uvedená adresa ale na .jsp
nekončí, takže se ji pokouší zpracovat přímo Apache -- zkusí tedy otevřít adresář /srv/tomcat6/webapps/kramerius
a tam hledá postupně index.html
, index.htm
a index.jsp
. Protože hlásí chybu 403, bude problém zřejmě v právech -- buď nemá uživatel, pod kterým běží Apache, právo vstoupit do adresáře /srv/tomcat6/webapps/kramerius
, nebo nemá právo číst některý z indexů, nebo nemá právo vypsat obsah adresáře.
Dekuji za typ, ale v pravech to neni. Prava jsem kontroloval v prubehu vcerejska. Prosel vsechny adresare a soubory a upravil tak, aby je mohl otevirat a cist kdokoliv.
index.jsp
na konci, tak to funguje? Nebo pokud si necháte od Apache poslat libovolný jiný soubor, který je v tom adresáři (vytvořte si tam třeba testovací txt soubor)?
Z adresare webapps/kramerius/ neni schopen zobrazit jediny soubor. Pritom do prohlizece je treba zadat i index.jsp, jinak je to liche. Ovsem na portu 8081 funguje bezvadne. Tam zobrazuje tomcat vsechno.
ls -l
.
Zde je obsah souboru httpd.conf:
### Global Environment ######################################################
#
# The directives in this section affect the overall operation of Apache,
# such as the number of concurrent requests.
# run under this user/group id
Include /etc/apache2/uid.conf
# - how many server processes to start (server pool regulation)
# - usage of KeepAlive
Include /etc/apache2/server-tuning.conf
# ErrorLog: The location of the error log file.
# If you do not specify an ErrorLog directive within a <VirtualHost>
# container, error messages relating to that virtual host will be
# logged here. If you *do* define an error logfile for a <VirtualHost>
# container, that host's errors will be logged there and not here.
ErrorLog /var/log/apache2/error_log
# generated from APACHE_MODULES in /etc/sysconfig/apache2
Include /etc/apache2/sysconfig.d/loadmodule.conf
# IP addresses / ports to listen on
Include /etc/apache2/listen.conf
# predefined logging formats
Include /etc/apache2/mod_log_config.conf
# generated from global settings in /etc/sysconfig/apache2
Include /etc/apache2/sysconfig.d/global.conf
# optional mod_status, mod_info
Include /etc/apache2/mod_status.conf
Include /etc/apache2/mod_info.conf
# optional cookie-based user tracking
# read the documentation before using it!!
Include /etc/apache2/mod_usertrack.conf
# configuration of server-generated directory listings
Include /etc/apache2/mod_autoindex-defaults.conf
# associate MIME types with filename extensions
TypesConfig /etc/apache2/mime.types
DefaultType text/plain
Include /etc/apache2/mod_mime-defaults.conf
# set up (customizable) error responses
Include /etc/apache2/errors.conf
# global (server-wide) SSL configuration, that is not specific to
# any virtual host
Include /etc/apache2/ssl-global.conf
# forbid access to the entire filesystem by default
<Directory />
Options None
AllowOverride None
Order deny,allow
Deny from all
</Directory>
# use .htaccess files for overriding,
AccessFileName .htaccess
# and never show them
<Files ~ "^\.ht">
Order allow,deny
Deny from all
</Files>
# List of resources to look for when the client requests a directory
DirectoryIndex index.html index.html.var
### 'Main' server configuration #############################################
#
# The directives in this section set up the values used by the 'main'
# server, which responds to any requests that aren't handled by a
# <VirtualHost> definition. These values also provide defaults for
# any <VirtualHost> containers you may define later in the file.
#
# All of these directives may appear inside <VirtualHost> containers,
# in which case these default settings will be overridden for the
# virtual host being defined.
#
Include /etc/apache2/default-server.conf
# Another way to include your own files
#
# The file below is generated from /etc/sysconfig/apache2,
# include arbitrary files as named in APACHE_CONF_INCLUDE_FILES and
# APACHE_CONF_INCLUDE_DIRS
Include /etc/apache2/sysconfig.d/include.conf
### Virtual server configuration ############################################
#
# VirtualHost: If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs-2.2/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.
#
Include /etc/apache2/vhosts.d/*.conf
# Note: instead of adding your own configuration here, consider
# adding it in your own file (/etc/apache2/httpd.conf.local)
# putting its name into APACHE_CONF_INCLUDE_FILES in
# /etc/sysconfig/apache2 -- this will make system updates
# easier :)
#Pridano pro virtualni hosty JSP:
Include /usr/share/tomcat6/conf/jk/mod_jk.conf-auto
Bohuzel ted nemam k dispozici vypis adresare, protoze ona masina se nachyzi u meho zamestanavatele. Nicmene konfiguraky jsem si zazalohoval vsechny k sobe na flashdisc. Snad to pomuze a chybu odhalime co nejdriv.
<Directory /> Options None AllowOverride None Order deny,allow Deny from all </Directory>Tady zakazujete přístup všem, a nevidím nikde dál pro příslušný adresář povolení přístupu.
Provedl jsem konfiguraci presne podle dokumentace, ...Nepochadza nahodou ta dokumentacia z cias, ked Apache 1.3 bol horucou novinkou? Pokial viem,
mod_jk
je uz poriadne dlho zastaraly. Odporucam pouzit mod_proxy_ajp
, funguje vyborne.
Nene, nepochazi. mod_jk se dockal vylepseni do verze 3 a je doporuceny od apache verze 2. Dokumentace je k posledni verzi tomcatu.
V konfigu Apache mate:
<Directory />
...
Deny from all
</Directory>
Zkuste do Virtualhostu pridat:
<Directory>
...
Order allow,deny
Allow from all
</Directory>
Tak v tomto problem neni. Chovani apache je stale stejne . Konfigurak apache jsem upravil, ale nic se nemeni.
V logu apache2 je nyni chyba File does not exist: /srv/tomcat6/webapps/kramerius/Welcome.do. Pritom tento soubor neni napriklad ani v /examples/jsp/security/protected/index.jsp kde apache s tomcatem bezi.
Jeste abych to uvedl na pravou miru:srv/tomcat6/webapps/examples/jsp/security/protected/index.jsp
Vyreseno . Zminovany soubor, resp. priponu *.do bylo treba pridat do mod_jk.conf prikazem JkMount.
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.