Apache 2.4无法识别其他站点-404错误

问题描述

背景:我在RHEL 7上运行Apache 2.4.25。现有网站已经存在多年,现在我想添加一个其他不相关的运行Angular的网站。

主要问题:无论我做什么,我都无法将流量路由到新网站。

预期的行为:现有站点在8443上继续运行,新站点在10443上运行。

实际行为:现有站点在8443和10443上侦听,但是新站点在这两者上都返回404

文件系统位置

  • Apache服务器:/ opt / intapache /
  • 现有(功能性)网站:/ opt / cspgateway /
  • 新的(非功能性)站点:/ opt / intapache / htdocs /(注意:此目录中的index.html设置为755文件访问权限)

当前文件:http.conf指向第二个conf

httpd.conf:

ServerRoot "/opt/intapache/"

Listen 8443

LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authn_core_module modules/mod_authn_core.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
LoadModule authz_user_module modules/mod_authz_user.so
LoadModule authz_core_module modules/mod_authz_core.so
LoadModule access_compat_module modules/mod_access_compat.so
LoadModule auth_basic_module modules/mod_auth_basic.so
LoadModule socache_shmcb_module modules/mod_socache_shmcb.so
LoadModule socache_dbm_module modules/mod_socache_dbm.so
LoadModule socache_memcache_module modules/mod_socache_memcache.so
LoadModule reqtimeout_module modules/mod_reqtimeout.so
LoadModule filter_module modules/mod_filter.so
LoadModule mime_module modules/mod_mime.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule env_module modules/mod_env.so
LoadModule headers_module modules/mod_headers.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule version_module modules/mod_version.so
LoadModule ssl_module modules/mod_ssl.so
LoadModule unixd_module modules/mod_unixd.so
LoadModule status_module modules/mod_status.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule dir_module modules/mod_dir.so
LoadModule alias_module modules/mod_alias.so

<IfModule unixd_module>
    User cachedb
    Group cachedb
</IfModule>

ServerAdmin [email protected]

ServerName example.com

<Directory />
    AllowOverride none
    Require all denied
</Directory>

DocumentRoot "/opt/cspgateway/csp"
<Directory "/opt/cspgateway/csp">
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>

<Files ".ht*">
    Require all denied
</Files>

ErrorLog "logs/error_log"

LogLevel warn

<IfModule log_config_module>
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common

    <IfModule logio_module>
        LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    </IfModule>

    CustomLog "logs/access_log" common

</IfModule>

<IfModule alias_module>
    ScriptAlias /cgi-bin/ "/opt/intapache//cgi-bin/"
</IfModule>

<IfModule cgid_module>
</IfModule>

<Directory "/opt/intapache/cgi-bin">
    AllowOverride None
    Options None
    Require all granted
</Directory>

<IfModule headers_module>
    RequestHeader unset Proxy early
</IfModule>

<IfModule mime_module>
    TypesConfig conf/mime.types

    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
</IfModule>

<IfModule proxy_html_module>
    Include conf/extra/proxy-html.conf
</IfModule>

<IfModule ssl_module>
    SSLRandomSeed startup builtin
    SSLRandomSeed connect builtin
</IfModule>

Include conf/extra/cspgateway.conf 

cspgateway.conf

<VirtualHost *:8443>
    DocumentRoot /opt/cspgateway/csp
    ServerName example.com

    SSLEngine on
    SSLCertificateFile "/opt/example.crt"
    SSLCertificateKeyFile "/opt/example.key"
    SSLCertificateChainFile "/opt/chaincert.crt"

    SSLProtocol All -SSLv2 -SSLv3 +TLSv1.2

</VirtualHost>


Listen 10443
<VirtualHost *:10443>
    DocumentRoot /opt/intapache/htdocs
    ServerName example.com

    SSLEngine on
    SSLCertificateFile "/opt/example.crt"
    SSLCertificateKeyFile "/opt/example.key"
    SSLCertificateChainFile "/opt/chaincert.crt"
    SSLProtocol All -SSLv2 -SSLv3 +TLSv1.2

    <Directory "/opt/intapache/htdocs">
        AllowOverride None
        Options Indexes FollowSymLinks
        Require all granted
    </Directory>
</VirtualHost>

LoadModule csp_module_sa /opt/cspgateway/bin/CSPa24.so
CSPModulePath /opt/cspgateway/bin/

<Location "/csp/bin/Systems/">
    SetHandler cspsys-handler-sa
</Location>
<Location "/csp/bin/RunTime/">
    SetHandler csp-handler-sa
</Location>

<Location />
    CSP On
</Location>

CSPFileTypes csp cls zen cxw gif jpeg jpg jpe png sgi svg svgz tiff tif ico
Alias /csp/ /opt/cspgateway/csp/
<Directory "/opt/cspgateway/csp">
     AllowOverride None
     Options MultiViews FollowSymLinks ExecCGI
     Order allow,deny
     Allow from all
     <FilesMatch "\.(log|ini|pid|exe)$">
         Deny from all
     </FilesMatch>
</Directory>


## START SDS-POC CONfig ##
<Directory "/opt/intapache/htdocs">
    AllowOverride None
    Options MultiViews FollowSymLinks ExecCGI
    Require all granted
</Directory>
## END SDS-POC CONfig ##


SSLSessionCache "shmcb:logs/ssl_scache(512000)"

解决方法

在提供有限信息的情况下,我构建了此配置。

httpd.conf

ServerRoot "/opt/intapache/"

LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authn_core_module modules/mod_authn_core.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
LoadModule authz_user_module modules/mod_authz_user.so
LoadModule authz_core_module modules/mod_authz_core.so
LoadModule access_compat_module modules/mod_access_compat.so
LoadModule auth_basic_module modules/mod_auth_basic.so
LoadModule socache_shmcb_module modules/mod_socache_shmcb.so
LoadModule socache_dbm_module modules/mod_socache_dbm.so
LoadModule socache_memcache_module modules/mod_socache_memcache.so
LoadModule reqtimeout_module modules/mod_reqtimeout.so
LoadModule filter_module modules/mod_filter.so
LoadModule mime_module modules/mod_mime.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule env_module modules/mod_env.so
LoadModule headers_module modules/mod_headers.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule version_module modules/mod_version.so
LoadModule ssl_module modules/mod_ssl.so
LoadModule unixd_module modules/mod_unixd.so
LoadModule status_module modules/mod_status.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule dir_module modules/mod_dir.so
LoadModule alias_module modules/mod_alias.so

<IfModule unixd_module>
    User cachedb
    Group cachedb
</IfModule>

ServerAdmin [email protected]

<Directory />
    AllowOverride none
    Require all denied
</Directory>

<Files ".ht*">
    Require all denied
</Files>


<IfModule log_config_module>
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common

    <IfModule logio_module>
        LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    </IfModule>
</IfModule>

<IfModule alias_module>
    ScriptAlias /cgi-bin/ "/opt/intapache//cgi-bin/"
</IfModule>

<IfModule cgid_module>
</IfModule>

<Directory "/opt/intapache/cgi-bin">
    AllowOverride None
    Options None
    Require all granted
</Directory>

<IfModule headers_module>
    RequestHeader unset Proxy early
</IfModule>

<IfModule mime_module>
    TypesConfig conf/mime.types

    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
</IfModule>

<IfModule ssl_module>
    SSLRandomSeed startup builtin
    SSLRandomSeed connect builtin

    SSLSessionCache "shmcb:logs/ssl_scache(512000)"
</IfModule>

Include conf/extra/cspgateway.conf 

conf / extra / cspgateway.conf

Listen 8443
<VirtualHost *:8443>
    ServerName OLD-example.com

    CustomLog "logs/8443_access_log" combined
    ErrorLog "logs/8443_error_log"
    LogLeval debug

    SSLEngine on
    SSLCertificateFile "/opt/OLD-example.crt"
    SSLCertificateKeyFile "/opt/OLD-example.key"
    SSLCertificateChainFile "/opt/OLD-chaincert.crt"

    SSLProtocol All -SSLv2 -SSLv3 +TLSv1.2
  
    DirectoryIndex index.html

    LoadModule csp_module_sa /opt/cspgateway/bin/CSPa24.so
    CSPModulePath /opt/cspgateway/bin/

    <Location />
        CSP On
    </Location>
    <Location "/csp/bin/Systems/">
        SetHandler cspsys-handler-sa
    </Location>
    <Location "/csp/bin/RunTime/">
        SetHandler csp-handler-sa
    </Location>

    CSPFileTypes csp cls zen cxw gif jpeg jpg jpe png sgi svg svgz tiff tif ico
    DocumentRoot "/opt/cspgateway/csp"
    Alias /csp/ /opt/cspgateway/csp/
    <Directory "/opt/cspgateway/csp">
         AllowOverride None
         Options MultiViews FollowSymLinks ExecCGI
         Order allow,deny
         Allow from all
         <FilesMatch "\.(log|ini|pid|exe)$">
             Deny from all
         </FilesMatch>
    </Directory>

</VirtualHost>

Listen 10443
<VirtualHost *:10443>
    ServerName NEW-example.com

    CustomLog "logs/10443_access_log" combined
    ErrorLog "logs/10443_error_log"
    LogLeval debug

    SSLEngine on
    SSLCertificateFile "/opt/NEW-example.crt"
    SSLCertificateKeyFile "/opt/NEW-example.key"
    SSLCertificateChainFile "/opt/NEW-chaincert.crt"
    SSLProtocol All -SSLv2 -SSLv3 +TLSv1.2

    DocumentRoot /opt/intapache/htdocs
    <Directory "/opt/intapache/htdocs">
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
    </Directory>

    DirectoryIndex index.html
</VirtualHost>

已完成

  • 将两个站点分开,每个站点都放在单独的VirtualHost中。
  • 拆分日志文件,每个VirtualHost一个。这有助于调试每个站点的状况。我现在还设置了LogLevel debug,一旦可以正常工作,就应该将其设置为不那么冗长。
  • 为SSL设置不同的证书。如果您确实希望两个站点都具有相同的域名,则可以撤消此操作。因为您使用了不同的端口,所以这里是可能的。
  • 与每个站点相关的所有配置都包含在其正确的VirtualHost中。例如目录或CSP模块。我有一种直觉,因为这个模块是在之前的通用部​​分中加载的,所以它在8844和10443的两个连接上都被激活。据我所知,它应该仅在8844的连接上才是活动的,我在这里做了。
  • 只有8443具有选项Options MultiViews FollowSymLinks ExecCGI。对于10443,它使用“常规”选项来提供html页面及其资源。
  • SSLSessionCache已移至httpd.conf,因为这是一个通用指令。
  • 我删除了以下伪指令:Include conf/extra/proxy-html.conf。没有加载的模块,没有指令。

以这种方式进行操作可确保每个站点彼此独立。尽管我不知道CSP的作用,但我猜想它在两个站点上都不应该处于活动状态,因此将其移至8443 VirtualHost中。

最后一点,应在服务器上打开端口8443和10443,以允许客户端连接到它们。


如果这不起作用,请提出一个新问题,并包括:

  • 配置文件
  • 日志条目
  • 预期行为
  • 当前行为
  • 尽可能多的细节!