George Georgallides
George Georgallides

Reputation: 300

mod_jk gives Bad gateway

I have Oracle mapviewer running on glassfish server version 4.1. It has been running with no problems on port 8080. The operating system is Oracle Linux 4.1.12-61.1.22.el6uek.x86_64. Recently we have decided to access glassfish applications through Apache webserver, version 2.2, so that we will have greater flexibility. Mod_jk 1.2 has been installed and seems to be working since I get "initialized" in the mod_jk.log file.

I have updated httpd.conf with the following:

LoadModule jk_module modules/mod_jk.so

# We need a workers file exactly once
# and in the global server
JkWorkersFile conf/workers.properties

# Our JK error log
# You can (and should) use rotatelogs here
JkLogFile logs/mod_jk.log

# Our JK log level (trace,debug,info,warn,error)
JkLogLevel info

# Our JK shared memory file
JkShmFile logs/mod_jk.shm

# Define a new log format you can use in any CustomLog in order
# to add mod_jk specific information to your access log.
# LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" \"%{Cookie}i\" \"%{Set-Cookie}o\" %{pid}P %{tid}P %{JK_LB_FIRST_NAME}n %{JK_LB_LAST_NAME}n ACC %{JK_LB_LAST_ACCESSED}n ERR %{JK_LB_LAST_ERRORS}n BSY %{JK_LB_LAST_BUSY}n %{JK_LB_LAST_STATE}n %D" extended_jk

# This option will reject all requests, which contain an
# encoded percent sign (%25) or backslash (%5C) in the URL
# If you are sure, that your webapp doesn't use such
# URLs, enable the option to prevent double encoding attacks.
# Since: 1.2.24
# JkOptions +RejectUnsafeURI

# This option will collapse multiple adjacent slashes
# in request URLs before looking for mount or unmount
# matches.
# Since: 1.2.41
# JkOptions +CollapseSlashesAll

# After setting JkStripSession to "On", mod_jk will
# strip all ";jsessionid=..." from request URLs it
# does *not* forward to a backend.
# This is useful, if all links in a webapp use
# URLencoded session IDs and parts of the static
# content should be delivered directly by Apache.
# Of course you can also do it with mod_rewrite.
# Since: 1.2.21
# JkStripSession On

# Start a separate thread for internal tasks like
# idle connection probing, connection pool resizing
# and load value decay.
# Run these tasks every JkWatchdogInterval seconds.
# Since: 1.2.27
JkWatchdogInterval 60

# Configure access to jk-status and jk-manager
# If you want to make this available in a virtual host,
# either move this block into the virtual host
# or copy it logically there by including "JkMountCopy On"
# in the virtual host.
# Add an appropriate authentication method here!
<Location /jk-status>
    # Inside Location we can omit the URL in JkMount
    JkMount jk-status
    Order deny,allow
    Deny from all
    Allow from 127.0.0.1
</Location>
<Location /jk-manager>
    # Inside Location we can omit the URL in JkMount
    JkMount jk-manager
    Order deny,allow
    Deny from all
    Allow from 127.0.0.1
</Location>

#<Location /mapviewer>
#    # Inside Location we can omit the URL in JkMount
#    JkMount mapviewer
#    Order deny,allow
#    Deny from all
#    Allow from 127.0.0.1
#</Location>

# If you want to put all mounts into an external file
# that gets reloaded automatically after changes
# (with a default latency of 1 minute),
# you can define the name of the file here.
# JkMountFile conf/extra/uriworkermap.properties

# Send all /mapviewer/ requests to Glassfish.
JkMount /gsmapviewer/* mapviewer

# Example for Mounting a context to the worker "balancer"
# The URL syntax "a|b" instantiates two mounts at once,
# the first one is "a", the second one is "ab".
# JkMount /myapp|/* balancer

# Example for UnMounting requests for all workers
# using a simple URL pattern
# Since: 1.2.26
# JkUnMount /myapp/static/* *

# Example for UnMounting requests for a named worker
# JkUnMount /myapp/images/* balancer

# Example for UnMounting requests using regexps
# SetEnvIf REQUEST_URI "\.(htm|html|css|gif|jpg|js)$" no-jk

# Example for setting a reply timeout depending on the request URL
# Since: 1.2.27
# SetEnvIf Request_URI "/transactions/" JK_REPLY_TIMEOUT=600000

# Example for disabling reply timeouts for certain request URLs
# Since: 1.2.27
# SetEnvIf Request_URI "/reports/" JK_REPLY_TIMEOUT=0

# IMPORTANT: Mounts and virtual hosts
# If you are using VirtualHost elements, you
# - can put mounts only used in some virtual host into its VirtualHost element 
# - can copy all global mounts to it using "JkMountCopy On" inside the VirtualHost
# - can copy all global mounts to all virtual hosts by putting
#   "JkMountCopy All" into the global server
# Since: 1.2.26

My workers.properties file:

worker.list=jk-status
worker.jk-status.type=status

worker.jk-status.read_only=true

worker.list=jk-manager
worker.jk-manager.type=status

worker.list=mapviewer

# Mapviewer worker.
worker.mapviewer.host=localhost
worker.mapviewer.port=8009
worker.mapviewer.type=ajp13
worker.mapviewer.lbfactor=1

# Activation allows to configure
# whether this node should actually be used
# A: active (use node fully)
# D: disabled (only use, if sticky session needs this node)
# S: stopped (do not use)
#   Since: 1.2.19
worker.mapviewer.activation=A

I have also created in glassfish asadmin the following listeners:

create-http-listener --listenerport 8009 --listeneraddress 0.0.0.0 --defaultvs server jk-http
create-network-listener --protocol http-listener-1 --listenerport 8009 --jkenabled true jk-connector

The problem is, when I try to access http://localhost/gsmapviewer/, I get Bad gateway error. In the mod_jk.log file I get:

[Sun Jun 18 10:51:47.024 2017] [29684:140425951717344] [info] init_jk::mod_jk.c (3595): mod_jk/1.2.42 initialized
[Sun Jun 18 10:52:23.033 2017] [4781:140425951717344] [info] ajp_connection_tcp_get_message::jk_ajp_common.c (1342): (mapviewer) can't receive the response header message from tomcat, tomcat (127.0.0.1:8009) has forced a connection close for socket 14
[Sun Jun 18 10:52:24.379 2017] [4781:140425951717344] [error] ajp_get_reply::jk_ajp_common.c (2259): (mapviewer) Tomcat is down or refused connection. No response has been sent to the client (yet)
[Sun Jun 18 10:52:24.379 2017] [4781:140425951717344] [info] ajp_service::jk_ajp_common.c (2778): (mapviewer) sending request to tomcat failed (recoverable),  (attempt=1)
[Sun Jun 18 10:52:55.038 2017] [4781:140425951717344] [info] ajp_connection_tcp_get_message::jk_ajp_common.c (1342): (mapviewer) can't receive the response header message from tomcat, tomcat (127.0.0.1:8009) has forced a connection close for socket 14
[Sun Jun 18 10:52:55.038 2017] [4781:140425951717344] [error] ajp_get_reply::jk_ajp_common.c (2259): (mapviewer) Tomcat is down or refused connection. No response has been sent to the client (yet)
[Sun Jun 18 10:52:55.038 2017] [4781:140425951717344] [info] ajp_service::jk_ajp_common.c (2778): (mapviewer) sending request to tomcat failed (recoverable),  (attempt=2)
[Sun Jun 18 10:52:55.038 2017] [4781:140425951717344] [error] ajp_service::jk_ajp_common.c (2799): (mapviewer) connecting to tomcat failed (rc=0, errors=1, client_errors=0).
[Sun Jun 18 10:52:55.038 2017] [4781:140425951717344] [info] jk_handler::mod_jk.c (2995): Service error=0 for worker=mapviewer

Upvotes: 1

Views: 1364

Answers (1)

fhossfel
fhossfel

Reputation: 2191

I think the second command is wrong. It should be

asadmin set server-config.network-config.network-listeners.network-listener.http-jk.jk-enabled=true

Not sure if that will still work with the second nework listener in place. I have the suspicion that you have to remove that first.

Upvotes: 2

Related Questions