AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 486093
Accepted
Darrell Brogdon
Darrell Brogdon
Asked: 2013-03-09 10:47:21 +0800 CST2013-03-09 10:47:21 +0800 CST 2013-03-09 10:47:21 +0800 CST

通过 mod_proxy_ajp 的 Apache 反向代理不将请求路由到 Tomcat

  • 772

我安装了 Apache 和 Tomcat7 的两个实例。一个在装有 Mountain Lion 的 Macbook Pro 上,另一个在装有 Ubuntu Server 12.10 的 Mac 上的 VirtualBox VM 中。两者具有相同的 VirtualHost 配置和 server.xml 配置。

在我的 Mac 上一切正常,但在 Ubuntu VM 上我收到“文件不存在”错误。

当我将 LogLevel 设置为 'debug' 时,日志输出看起来几乎相同。

有没有其他地方我可以看看为什么请求没有被代理到 Tomcat?

这是我的配置文件。

服务器.xml:

<?xml version='1.0' encoding='utf-8'?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<!-- Note:  A "Server" is not itself a "Container", so you may not
     define subcomponents such as "Valves" at this level.
     Documentation at /docs/config/server.html
 -->
<Server port="8005" shutdown="SHUTDOWN">
  <!-- Security listener. Documentation at /docs/config/listeners.html
  <Listener className="org.apache.catalina.security.SecurityListener" />
  -->
  <!--APR library loader. Documentation at /docs/apr.html -->
  <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
  <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.GlobalResourcesLifecycleListener" />
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />

  <!-- Global JNDI resources
       Documentation at /docs/jndi-resources-howto.html
  -->
  <GlobalNamingResources>
    <!-- Editable user database that can also be used by
         UserDatabaseRealm to authenticate users
    -->
    <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>

  <!-- A "Service" is a collection of one or more "Connectors" that share
       a single "Container" Note:  A "Service" is not itself a "Container",
       so you may not define subcomponents such as "Valves" at this level.
       Documentation at /docs/config/service.html
   -->
  <Service name="Catalina">

    <!--The connectors can use a shared executor, you can define one or more named thread pools-->
    <!--
    <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
        maxThreads="150" minSpareThreads="4"/>
    -->


    <!-- A "Connector" represents an endpoint by which requests are received
         and responses are returned. Documentation at :
         Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
         Java AJP  Connector: /docs/config/ajp.html
         APR (HTTP/AJP) Connector: /docs/apr.html
         Define a non-SSL HTTP/1.1 Connector on port 8080
    -->
    <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    <!-- A "Connector" using the shared thread pool-->
    <!--
    <Connector executor="tomcatThreadPool"
               port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    -->
    <!-- Define a SSL HTTP/1.1 Connector on port 8443
         This connector uses the JSSE configuration, when using APR, the
         connector should be using the OpenSSL style configuration
         described in the APR documentation -->
    <!--
    <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
               maxThreads="150" scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS" />
    -->

    <!-- Define an AJP 1.3 Connector on port 8009 -->
    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />


    <!-- An Engine represents the entry point (within Catalina) that processes
         every request.  The Engine implementation for Tomcat stand alone
         analyzes the HTTP headers included with the request, and passes them
         on to the appropriate Host (virtual host).
         Documentation at /docs/config/engine.html -->

    <!-- You should set jvmRoute to support load-balancing via AJP ie :
    <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
    -->
    <Engine name="Catalina" defaultHost="localhost">

      <!--For clustering, please take a look at documentation at:
          /docs/cluster-howto.html  (simple how to)
          /docs/config/cluster.html (reference documentation) -->
      <!--
      <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
      -->

      <!-- Use the LockOutRealm to prevent attempts to guess user passwords
           via a brute-force attack -->
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <!-- This Realm uses the UserDatabase configured in the global JNDI
             resources under the key "UserDatabase".  Any edits
             that are performed against this UserDatabase are immediately
             available for use by the Realm.  -->
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>
      </Realm>

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

        <!-- SingleSignOn valve, share authentication between web applications
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
        -->

        <!-- Access log processes all example.
             Documentation at: /docs/config/valve.html
             Note: The pattern used is equivalent to using pattern="common" -->
        <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>
    </Engine>
  </Service>
</Server>

代理配置文件:

<IfModule mod_proxy.c>                                                                  

# If you want to use apache2 as a forward proxy, uncomment the                          
# 'ProxyRequests On' line and the <Proxy *> block below.                                
# WARNING: Be careful to restrict access inside the <Proxy *> block.                    
# Open proxy servers are dangerous both to your network and to the                      
# Internet at large.                                                                    
#                                                                                       
# If you only want to use apache2 as a reverse proxy/gateway in                         
# front of some web application server, you DON'T need                                  
# 'ProxyRequests On'.                                                                   

ProxyRequests On                                                                        
#<Proxy *>                                                                              
#        AddDefaultCharset off                                                          
#        Order deny,allow                                                               
#        Deny from all                                                                  
#        #Allow from .example.com                                                       
#</Proxy>                                                                               
<Proxy *>                                                                               
    AddDefaultCharset Off                                                               
    Order deny,allow                                                                    
    Allow from all                                                                      
</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 Off                                                                           

</IfModule>

虚拟主机:

<VirtualHost *:80>                                                                      
    DocumentRoot "/home/dbrogdon/development/app/application/portal/src/main/webapp/"
    ServerName ubuntu.dev                                                               
    ErrorLog ${APACHE_LOG_DIR}/ubuntu.dev.error.log                                     
    CustomLog ${APACHE_LOG_DIR}/ubuntu.dev.access.log combined                          
    LogLevel debug                                                                      

    ProxyPass /portal/api-v1 ajp://127.0.0.1:8009/portal/api-v1                         
    ProxyPassReverse /portal/api-v1 ajp://127.0.0.1:8009/portal/api-v1                  

    ProxyPass /portal/jsp ajp://127.0.0.1:8009/portal/jsp                               
    ProxyPassReverse /portal/jsp ajp://127.0.0.1:8009/portal/jsp                        

    ProxyPass /portal/j_spring_security_check ajp://127.0.0.1:8009/portal/j_spring_security_check
    ProxyPassReverse /portal/j_spring_security_check ajp://127.0.0.1:8009/portal/j_spring_security_check

    <Directory "/home/dbrogdon/development/app/application/portal/src/main/webapp/">
        Options -Indexes FollowSymLinks                                                 
        AllowOverride AuthConfig FileInfo                                               
        Order allow,deny                                                                
        Allow from all                                                                  
    </Directory>                                                                        
</VirtualHost>

日志输出:

[Fri Mar 08 07:45:41 2013] [debug] mod_proxy_ajp.c(45): proxy: AJP: canonicalising URL //127.0.0.1:8009/portal/jsp/login.jsp
[Fri Mar 08 07:45:41 2013] [debug] proxy_util.c(1506): [client 192.168.2.18] proxy: ajp: found worker ajp://127.0.0.1:8009/portal/jsp for ajp://127.0.0.1:8009/portal/jsp/login.jsp
[Fri Mar 08 07:45:41 2013] [debug] mod_proxy.c(1020): Running scheme ajp handler (attempt 0)
[Fri Mar 08 07:45:41 2013] [debug] mod_proxy_ajp.c(681): proxy: AJP: serving URL ajp://127.0.0.1:8009/portal/jsp/login.jsp
[Fri Mar 08 07:45:41 2013] [debug] proxy_util.c(2011): proxy: AJP: has acquired connection for (127.0.0.1)
[Fri Mar 08 07:45:41 2013] [debug] proxy_util.c(2067): proxy: connecting ajp://127.0.0.1:8009/portal/jsp/login.jsp to 127.0.0.1:8009
[Fri Mar 08 07:45:41 2013] [debug] proxy_util.c(2193): proxy: connected /portal/jsp/login.jsp to 127.0.0.1:8009
[Fri Mar 08 07:45:41 2013] [debug] ajp_header.c(224): Into ajp_marshal_into_msgb
[Fri Mar 08 07:45:41 2013] [debug] ajp_header.c(290): ajp_marshal_into_msgb: Header[0] [Host] = [ubuntu.dev]
[Fri Mar 08 07:45:41 2013] [debug] ajp_header.c(290): ajp_marshal_into_msgb: Header[1] [Connection] = [keep-alive]
[Fri Mar 08 07:45:41 2013] [debug] ajp_header.c(290): ajp_marshal_into_msgb: Header[2] [Cache-Control] = [no-cache]
[Fri Mar 08 07:45:41 2013] [debug] ajp_header.c(290): ajp_marshal_into_msgb: Header[3] [Accept] = [text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8]
[Fri Mar 08 07:45:41 2013] [debug] ajp_header.c(290): ajp_marshal_into_msgb: Header[4] [Pragma] = [no-cache]
[Fri Mar 08 07:45:41 2013] [debug] ajp_header.c(290): ajp_marshal_into_msgb: Header[5] [User-Agent] = [Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.33 (KHTML, like Gecko) Chrome/27.0.1432.0 Safari/537.33]
[Fri Mar 08 07:45:41 2013] [debug] ajp_header.c(290): ajp_marshal_into_msgb: Header[6] [Accept-Encoding] = [gzip,deflate,sdch]
[Fri Mar 08 07:45:41 2013] [debug] ajp_header.c(290): ajp_marshal_into_msgb: Header[7] [Accept-Language] = [en-US,en;q=0.8]
[Fri Mar 08 07:45:41 2013] [debug] ajp_header.c(290): ajp_marshal_into_msgb: Header[8] [Accept-Charset] = [ISO-8859-1,utf-8;q=0.7,*;q=0.3]
[Fri Mar 08 07:45:41 2013] [debug] ajp_header.c(290): ajp_marshal_into_msgb: Header[9] [Cookie] = [JSESSIONID=FC550CC672F46C81CE57787EF77A7689]
[Fri Mar 08 07:45:41 2013] [debug] ajp_header.c(450): ajp_marshal_into_msgb: Done
[Fri Mar 08 07:45:41 2013] [debug] mod_proxy_ajp.c(268): proxy: APR_BUCKET_IS_EOS
[Fri Mar 08 07:45:41 2013] [debug] mod_proxy_ajp.c(273): proxy: data to read (max 8186 at 4)
[Fri Mar 08 07:45:41 2013] [debug] mod_proxy_ajp.c(288): proxy: got 0 bytes of data
[Fri Mar 08 07:45:41 2013] [debug] ajp_header.c(687): ajp_read_header: ajp_ilink_received 04
[Fri Mar 08 07:45:41 2013] [debug] ajp_header.c(697): ajp_parse_type: got 04
[Fri Mar 08 07:45:41 2013] [debug] ajp_header.c(516): ajp_unmarshal_response: status = 200
[Fri Mar 08 07:45:41 2013] [debug] ajp_header.c(537): ajp_unmarshal_response: Number of headers is = 2
[Fri Mar 08 07:45:41 2013] [debug] ajp_header.c(599): ajp_unmarshal_response: Header[0] [Content-Type] = [text/html;charset=ISO-8859-1]
[Fri Mar 08 07:45:41 2013] [debug] ajp_header.c(609): ajp_unmarshal_response: ap_set_content_type done
[Fri Mar 08 07:45:41 2013] [debug] ajp_header.c(599): ajp_unmarshal_response: Header[1] [Content-Length] = [1420]
[Fri Mar 08 07:45:41 2013] [debug] ajp_header.c(687): ajp_read_header: ajp_ilink_received 03
[Fri Mar 08 07:45:41 2013] [debug] ajp_header.c(697): ajp_parse_type: got 03
[Fri Mar 08 07:45:41 2013] [debug] ajp_header.c(687): ajp_read_header: ajp_ilink_received 05
[Fri Mar 08 07:45:41 2013] [debug] ajp_header.c(697): ajp_parse_type: got 05
[Fri Mar 08 07:45:41 2013] [debug] mod_proxy_ajp.c(590): proxy: got response from 127.0.0.1:8009 (127.0.0.1)
[Fri Mar 08 07:45:41 2013] [debug] proxy_util.c(2029): proxy: AJP: has released connection for (127.0.0.1)
[Fri Mar 08 07:45:41 2013] [error] [client 192.168.2.18] File does not exist: /home/dbrogdon/development/app/application/portal/src/main/webapp/portal, referer: http://ubuntu.dev/portal/jsp/login.jsp
apache-2.2
  • 1 1 个回答
  • 12013 Views

1 个回答

  • Voted
  1. Best Answer
    Giacomo1968
    2013-03-09T12:11:08+08:002013-03-09T12:11:08+08:00

    好的,两个想法。首先,在您的 Apache 配置中,为什么您有 3 个 URL 的 ProxyPass 设置,这些设置似乎都设置为存在/portal/?

    ProxyPass /portal/api-v1 ajp://127.0.0.1:8009/portal/api-v1                         
    ProxyPassReverse /portal/api-v1 ajp://127.0.0.1:8009/portal/api-v1                  
    
    ProxyPass /portal/jsp ajp://127.0.0.1:8009/portal/jsp                               
    ProxyPassReverse /portal/jsp ajp://127.0.0.1:8009/portal/jsp                        
    
    ProxyPass /portal/j_spring_security_check ajp://127.0.0.1:8009/portal/j_spring_security_check
    ProxyPassReverse /portal/j_spring_security_check ajp://127.0.0.1:8009/portal/j_spring_security_check
    

    如果可能的话,我建议将其简化为以下内容:

    ProxyPass /portal ajp://127.0.0.1:8009/portal/
    ProxyPassReverse /portal ajp://127.0.0.1:8009/portal/
    

    我还添加了这一点mod_rewrite以确保添加了尾部斜杠:

    # Settings for adding a trailing slash to the URL
    RewriteEngine On
    RewriteCond %{REQUEST_URI} ^/(portal)$
    RewriteRule ^(.*)$ http://%{HTTP_HOST}$1/ [R=301,L]
    

    另外,因为mod_proxy我这样做:

    # Proxy specific settings
    ProxyRequests Off
    ProxyPreserveHost On
    

    这将全部加起来像这样的 Apache 虚拟主机配置。我还建议回滚proxy.conf到您的默认设置。将所有需要的设置放在 VirtualHost 文件中,如下所示,这样你就不必做任何事情,但要确保配置文件在设置之间浮动,并且你不会将配置调整散布到所有类型的文件中:

    <VirtualHost *:80>                                                                      
        DocumentRoot "/home/dbrogdon/development/app/application/portal/src/main/webapp/"
        ServerName ubuntu.dev                                                               
        ErrorLog ${APACHE_LOG_DIR}/ubuntu.dev.error.log                                     
        CustomLog ${APACHE_LOG_DIR}/ubuntu.dev.access.log combined                          
        LogLevel debug                                                                      
    
        ProxyPass /portal ajp://127.0.0.1:8009/portal/
        ProxyPassReverse /portal ajp://127.0.0.1:8009/portal/
    
        # Settings for adding a trailing slash to the URL
        RewriteEngine On
        RewriteCond %{REQUEST_URI} ^/(portal)$
        RewriteRule ^(.*)$ http://%{HTTP_HOST}$1/ [R=301,L]
    
        # Settings for Apache Reverse Proxying
        <IfModule mod_proxy.c>
    
          # Proxy specific settings
          ProxyRequests Off
          ProxyPreserveHost On
    
          <Proxy *>
            AddDefaultCharset off
            Order deny,allow
            Allow from all
          </Proxy>
    
          ProxyPass /portal ajp://127.0.0.1:8009/portal/
          ProxyPassReverse /portal ajp://127.0.0.1:8009/portal/
    
        </IfModule>
    
        <Directory "/home/dbrogdon/development/app/application/portal/src/main/webapp/">
            Options -Indexes FollowSymLinks                                                 
            AllowOverride AuthConfig FileInfo                                               
            Order allow,deny                                                                
            Allow from all                                                                  
        </Directory>                                                                        
    
    </VirtualHost>
    

    在连接 Java Web 服务和 Apache 配置的世界时,这种设置对我来说总是非常有用。

    • 1

相关问题

  • Apache Django Mod_Wsgi - 自动重新加载应用程序

  • Apache:对多个虚拟主机使用相同的目录指令

  • Apache 上的子域不工作 - 找不到服务器

  • PHP 作为 CGI 还是 Apache 模块?

  • 避免将某些丢失的文件记录到 Apache2 错误日志中

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve