Warm tip: This article is reproduced from serverfault.com, please click

apache-为 Tomcat 代理应用程序获取 404

(apache - Getting 404 for Tomcat Proxy Application)

发布于 2021-05-25 02:13:10

我正在尝试设置 Tomcat 服务器。

以下是我的 VirtualHost 配置

<VirtualHost <hosting's ip>:80>
  ServerName myapp.com
    ServerAlias mail.myApp.com www.myapp.com
#  DocumentRoot /home/myappco/public_html
  ServerAdmin webmaster@myapp.com
  UseCanonicalName Off

  <IfModule userdir_module>
    <IfModule !mpm_itk.c>
      <IfModule !ruid2_module>
        <IfModule !mod_passenger.c>
          UserDir enabled myappco
        </IfModule>
      </IfModule>
    </IfModule>
  </IfModule>
 <IfModule include_module>
    <Directory "/home/myappco/public_html">
      SSILegacyExprParser On
    </Directory>
  </IfModule>

  <IfModule suphp_module>
    suPHP_UserGroup myappco myappco
  </IfModule>
  <IfModule suexec_module>
    <IfModule !mod_ruid2.c>
      SuexecUserGroup myappco myappco
    </IfModule>
  </IfModule>
  <IfModule ruid2_module>
    RMode config
    RUidGid myappco myappco
  </IfModule>
  <IfModule mpm_itk.c>
    AssignUserID myappco myappco
  </IfModule>
  <IfModule mod_passenger.c>
    PassengerUser myappco
    PassengerGroup myappco
  </IfModule>

  <IfModule alias_module>
    ScriptAlias /cgi-bin/ /home/myappco/public_html/cgi-bin/
  </IfModule>
    <IfModule rewrite_module>
        RewriteOptions Inherit
    </IfModule>

    <IfModule proxy_fcgi_module>
        <FilesMatch \.(phtml|php[0-9]*)$>
            SetHandler proxy:unix:/opt/cpanel/ea-php71/root/usr/var/run/php-fpm/11fd7156a043fa23ad7e496c622a3f2dcd557177.sock|fcgi://myapp.com
        </FilesMatch>
    </IfModule>

  # To customize this VirtualHost use an include file at the following location
  Include "/etc/apache2/conf.d/userdata/std/2_4/myappco/myapp.com/*.conf"
</VirtualHost>

我正在关注本教程https://documentation.cpanel.net/display/EA4/Tomcat+Proxies,因为它包含在 README.APACHE-PROXY 中,所以我基本上在指示的 *.conf 文件中添加了我的代理:

<IfModule proxy_ajp_module>
    ProxyPass "/myapp" "ajp://localhost:10001/myapp"
    ProxyPassReverse "/myapp" "ajp://localhost:10001/myapp"
</IfModule>

以下是我的server.xml

<?xml version="1.0" encoding="UTF-8"?>
<Server port="-1" shutdown="SHUTDOWN">
  <Listener className="org.apache.catalina.startup.VersionLoggerListener"/>
  <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on"/>
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/>
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener"/>
  <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">
<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" deployOnStartup="true" deployXML="false">
        <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.ErrorReportValve" showReport="false" showServerInfo="false"/>
      </Host>
    </Engine>
    <Connector port="10001" protocol="AJP/1.3" xpoweredBy="false" secretRequired="false" enableLookups="true"/>
  </Service>
</Server>

看起来代理工作正常,因为我在 Chrome Dev Tools 中看到 302 重定向状态,但是当它查询应用程序时我得到 404,即使 Tomcat 启动工作正常,表明 ajp 连接器正在侦听。请帮忙。我的选择不多了。

Questioner
bionia
Viewed
0
bionia 2021-06-05 13:42:31

该问题源于配置错误的 POM 文件,其中 index.html 文件被放置在 war 文件中的其他位置。我只是更改了目标目录路径来解决这个问题。为愚蠢的错误道歉。