在带有负载均衡器/OpenSSL 的 AWS Lightsail 上使用 Apache2 和 Tomcat8

Using Apache2 AND Tomcat8 on AWS Lightsail with Loadbalancer / OpenSSL

我是 运行 AWS Lightsail 网站,使用 Ubuntu 16.04.6 和 Apache 2.4 以及 Tomcat 8.0.32。

Apache2 站点托管我的大部分网站,因为它们使用 PHP 和 PostgreSQL。 Tomcat 很容易托管 Geoserver。

我在 AWS LightSail 上有一个 DNS 和负载均衡器。我正在尝试弄清楚如何使用虚拟主机使两个景点无缝连接。 apache2 站点运行正常,但 tomcats 站点运行不正常。我收到此错误

You don't have permission to access this resource.

Apache/2.4.18 (Ubuntu) Server at tomcat.some-kind-of-site.org Port 80

我正在尝试按照此说明进行操作,但设置与我的设置有些不同: http://www.creang.com/howtoforge/howto_set_up_tomcat_8_with_apache_2_4_and_mod_jk_on_ubuntu/

我在 default-ssl-conf 文件中有我的 SSL 信息

我的 tomcat8 server.xml 包含:

    <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />

    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

这是我的 sites-enabled 配置文件:

 <VirtualHost *:80>
     ServerAdmin someone@gmail.com
     ServerName www.some-kind-of-site.org
     RewriteEngine On
     RewriteCond %{HTTP:X-FORWARDED-PORT} !=443
     RewriteRule ^(.*)$ https://www.some-kind-of-site.org [R=301,NE,L]
     DocumentRoot /var/www/html/main-site/
     Alias /multi-site /var/www/html/multi-site
     Alias /file-folder /var/www/html/file-folder
     ErrorLog ${APACHE_LOG_DIR}/error.log
     CustomLog ${APACHE_LOG_DIR}/access.log combined
 </VirtualHost>
 <VirtualHost *:80>
     ServerName manage.some-kind-of-site.org
     DocumentRoot /var/www/html/main-mgmt/
     RewriteEngine On
     RewriteCond %{HTTP:X-FORWARDED-PORT} !=443
     RewriteRule ^(.*)$ https://manage.some-kind-of-site.org [R=301,NE,L]
     Alias /multi-site /var/www/html/multi-site
     Alias /file-folder /var/www/html/file-folder
     Alias /main-mgmt /var/www/html/main-mgmt
     Alias /main-site /var/www/html/main-site
     ErrorLog ${APACHE_LOG_DIR}/error.log
     CustomLog ${APACHE_LOG_DIR}/access.log combined
 </VirtualHost>
 <VirtualHost *:80>
     ServerAdmin someone@gmail.com
     ServerName tomcat.some-kind-of-site.org
     DocumentRoot /var/lib/tomcat8/
     Alias /multi-site /var/www/html
     RewriteEngine On
     RewriteCond %{HTTP:X-FORWARDED-PORT} !=443
     RewriteRule ^(.*)$ https://tomcat.some-kind-of-site.org [R=301,NE,L]
     ErrorLog ${APACHE_LOG_DIR}/error.log
     CustomLog ${APACHE_LOG_DIR}/access.log combined
 </VirtualHost>
 <VirtualHost *:80>
     ServerName geoserver.some-kind-of-site.org
     DocumentRoot /var/lib/tomcat8/webapps/geoserver/
     Alias /multi-site /var/www/html
     RewriteEngine On
     RewriteCond %{HTTP:X-FORWARDED-PORT} !=443
     RewriteRule ^(.*)$ https://geoserver.some-kind-of-site.org [R=301,NE,L]
     ErrorLog ${APACHE_LOG_DIR}/error.log
     CustomLog ${APACHE_LOG_DIR}/access.log combined
 </VirtualHost>
 <IfModule mod_ssl.c>
     <VirtualHost _default_:443>
         ServerAdmin someone@gmail.com
         ServerName www.some-kind-of-site.org
         DocumentRoot /var/www/html/main-site/
         Alias /multi-site /var/www/html/multi-site
         Alias /file-folder /var/www/html/file-folder
         ErrorLog ${APACHE_LOG_DIR}/main-site_error.log
         CustomLog ${APACHE_LOG_DIR}/main-site_access.log combined
     </VirtualHost>
     <VirtualHost _default_:443>
         ServerAdmin someone@gmail.com
         ServerName manage.some-kind-of-site.org
         DocumentRoot /var/www/html/main-mgmt/
         Alias /multi-site /var/www/html/multi-site
         Alias /file-folder /var/www/html/file-folder
         Alias /main-mgmt /var/www/html/main-mgmt
         Alias /main-site /var/www/html/main-site
         ErrorLog ${APACHE_LOG_DIR}/main-mgmt_error.log
         CustomLog ${APACHE_LOG_DIR}/main-mgmt_access.log combined
     </VirtualHost>
     <VirtualHost *:443>
         ServerAdmin someone@gmail.com
         ServerName tomcat.some-kind-of-site.org
        <Proxy *>
            AddDefaultCharset Off
            Order deny,allow
            Allow from all
            </Proxy>
            ProxyPass / ajp://localhost:8009/
            ProxyPassReverse / ajp://localhost:8009/
         ProxyPreserveHost on
     </VirtualHost>
     <VirtualHost *:443>
         ServerAdmin someone@gmail.com
         ServerName geoserver.some-kind-of-site.org
        <Proxy *>
            AddDefaultCharset Off
            Order deny,allow
            Allow from all
            </Proxy>
            ProxyPass / ajp://localhost:8009/webapps/geoserver/
            ProxyPassReverse / ajp://localhost:8009/webapps/geoserver/
         ProxyPreserveHost on
         </VirtualHost>
     <FilesMatch "\.(cgi|shtml|phtml|php)$">
         SSLOptions +StdEnvVars
     </FilesMatch>
 </IfModule>

谁能帮我解决这个问题??请!

我想出来了...不得不,没有人回答。但这花了很多时间和很多试错。

根本不要将 443 端口用于 tomcat 代理...

 <VirtualHost *:80>
     ServerAdmin someguy@gmail.com
     ServerName www.greatexamples.org
     RewriteEngine On
     RewriteCond %{HTTP:X-FORWARDED-PORT} !=443
     RewriteRule ^(.*)$ https://www.greatexamples.org [R=301,NE,L]
     DocumentRoot /var/www/html/mainsite/
     Alias /multi-site /var/www/html/multi-site
        Alias /old_stuff /var/www/html/old_stuff
     ErrorLog ${APACHE_LOG_DIR}/error.log
     CustomLog ${APACHE_LOG_DIR}/access.log combined
 </VirtualHost>
 <VirtualHost *:80>
     ServerName manage.greatexamples.org
     DocumentRoot /var/www/html/management/
     RewriteEngine On
     RewriteCond %{HTTP:X-FORWARDED-PORT} !=443
     RewriteRule ^(.*)$ https://manage.greatexamples.org [R=301,NE,L]
     Alias /multi-site /var/www/html/multi-site
        Alias /old_stuff /var/www/html/old_stuff
        Alias /management /var/www/html/management
        Alias /mainsite /var/www/html/mainsite
     ErrorLog ${APACHE_LOG_DIR}/error.log
     CustomLog ${APACHE_LOG_DIR}/access.log combined
 </VirtualHost>
 <VirtualHost *:80>
     ServerAdmin someguy@gmail.com
     ServerName tomcat.greatexamples.org
     DocumentRoot /opt/tomcat/
     ProxyRequests Off
    <Proxy *>
      Order deny,allow
      Allow from all
    </Proxy>
    <Location />
      Order allow,deny
      Allow from all
    </Location>
            ProxyPass / http://localhost:8080/
            ProxyPassReverse / http://tomcat.greatexamples.org:8080/
     ErrorLog ${APACHE_LOG_DIR}/error.log
     CustomLog ${APACHE_LOG_DIR}/access.log combined
 </VirtualHost>
 <IfModule mod_ssl.c>
     <VirtualHost _default_:443>
         ServerAdmin someguy@gmail.com
         ServerName www.greatexamples.org
         DocumentRoot /var/www/html/mainsite/
         Alias /multi-site /var/www/html/multi-site
         Alias /file-folder /var/www/html/old_stuff
         ErrorLog ${APACHE_LOG_DIR}/main-site_error.log
         CustomLog ${APACHE_LOG_DIR}/main-site_access.log combined
     </VirtualHost>
     <VirtualHost _default_:443>
         ServerAdmin someguy@gmail.com
         ServerName manage.greatexamples.org
         DocumentRoot /var/www/html/management/
        Alias /multi-site /var/www/html/multi-site
        Alias /old_stuff /var/www/html/old_stuff
        Alias /management /var/www/html/old_stuff
        Alias /mainsite /var/www/html/mainsite
         ErrorLog ${APACHE_LOG_DIR}/main-mgmt_error.log
         CustomLog ${APACHE_LOG_DIR}/main-mgmt_access.log combined
     </VirtualHost>
 </IfModule>

并将 Tomcat 的 server.xml 中的连接器更改为:

<Connector port="8080" protocol="HTTP/1.1"
    connectionTimeout="20000"
    proxyName="tomcat.greatexamples.org"
    proxyPort="80"
    redirectPort="8443" />