简体   繁体   中英

Running multi tenancy on same port with apache web server - NameBasedVirtualHsoting

I have been working to get multi tenancy running on same port on same ip address. I have achieved the objective with different ports but I can't run the same on one port only. Here the apache web server redirects the request to weblogic host on same machine. I have gone through multiple guides but it is not working as expected. I have configured two virtual hosts for same port with URL as localhost:9010/site1 and localhost:9010/site2. The configuration in httpd.conf is mentioned below. I don't know where I have made the mistake so I have kept whole configuration file.

    Define SRVROOT "D:\Apache24"
    ServerRoot "${SRVROOT}"


    Listen 9010
    #Listen 9011


    LoadModule actions_module modules/mod_actions.so
    LoadModule alias_module modules/mod_alias.so
    LoadModule allowmethods_module modules/mod_allowmethods.so
    LoadModule asis_module modules/mod_asis.so
    LoadModule auth_basic_module modules/mod_auth_basic.so

    LoadModule authn_core_module modules/mod_authn_core.so
    LoadModule authn_file_module modules/mod_authn_file.so
    LoadModule authz_core_module modules/mod_authz_core.so
    LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
    LoadModule authz_host_module modules/mod_authz_host.so
    LoadModule authz_user_module modules/mod_authz_user.so
    LoadModule autoindex_module modules/mod_autoindex.so
    LoadModule cgi_module modules/mod_cgi.so
    LoadModule dir_module modules/mod_dir.so
    LoadModule env_module modules/mod_env.so
    LoadModule headers_module modules/mod_headers.so
    LoadModule include_module modules/mod_include.so
    LoadModule isapi_module modules/mod_isapi.so
    LoadModule log_config_module modules/mod_log_config.so
    LoadModule mime_module modules/mod_mime.so
    LoadModule negotiation_module modules/mod_negotiation.so
    LoadModule proxy_module modules/mod_proxy.so
    LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
    LoadModule proxy_html_module modules/mod_proxy_html.so
    LoadModule proxy_http_module modules/mod_proxy_http.so
    LoadModule setenvif_module modules/mod_setenvif.so
    LoadModule socache_shmcb_module modules/mod_socache_shmcb.so
    LoadModule ssl_module modules/mod_ssl.so
    LoadModule xml2enc_module modules/mod_xml2enc.so

    <IfModule unixd_module>
    User daemon
    Group daemon
    </IfModule>

    <Directory />
            AllowOverride ALL
            Require all granted
    </Directory>

    DocumentRoot "${SRVROOT}/htdocs"
    <Directory "${SRVROOT}/htdocs">
            Options Indexes FollowSymLinks
            AllowOverride None
            Require all granted
    </Directory>

    <IfModule dir_module>
            DirectoryIndex /home
    </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/ "${SRVROOT}/cgi-bin/"
    </IfModule>

    <IfModule cgid_module>
    </IfModule>

    <Directory "${SRVROOT}/cgi-bin">
            AllowOverride None
            Options None
            Require all granted
    </Directory>

    <IfModule mime_module>
            TypesConfig conf/mime.types
            AddType application/x-compress .Z
            AddType application/x-gzip .gz .tgz
            AddType text/css .css
            AddType text/javascript .js
    </IfModule>

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

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

    ProxyRequests on

    ProxyIOBufferSize 65536


    SSLProxyEngine on

    ErrorDocument 403 /home
    ErrorDocument 404 /home

    NameVirtualHost *:9010

    <VirtualHost *:9010>
        ServerName localhost:9010/site2
        LogLevel info

        <Location />
            SetHandler weblogic-handler
        </Location>

        ProxyPass /site2 http://localhost:7001
        ProxyPassReverse /site2 http://localhost:7001
        ProxyPass /Login.zul http://localhost:7001/Login.zul
        ProxyPassReverse /Login.zul http://localhost:7001/Login.zul

        <IfModule mod_weblogic.c>
            WebLogichost localhost
            WebLogicPort 7001
            debug OFF
            FileCaching OFF
            MatchExpression *
            KeepAliveSecs 540
        </IfModule>
    </VirtualHost>


    <VirtualHost localhost:9010>
        ServerName localhost:9010/site1
        LogLevel info

        <Location />
            SetHandler weblogic-handler
        </Location>

        ProxyPass /site1 http://localhost:7001
        ProxyPassReverse /site1 http://localhost:7001
        ProxyPass /Login.zul http://localhost:7001/Login.zul
        ProxyPassReverse /Login.zul http://localhost:7001/Login.zul
        <IfModule mod_weblogic.c>
            WebLogichost localhost
            WebLogicPort 7001
            debug OFF
            FileCaching OFF
            MatchExpression *
            KeepAliveSecs 540
        </IfModule>
    </VirtualHost>

Whenever I use different ports for site1 and site2, it runs fine. But keeping the same port does not work for me. Only the virtualhost defined first works and the other returns eorro 404. Also I found that it is called as Name based virtual hosting. The guides suggests that NameVirtualHost directive should be configured. I have also added the same.

Please help... Thank you in advance..

If you are running 2 VirtualHosts on the same port, the differentiator would be the Servername, such as:

<VirtualHost *:9010>
      ServerName site1.localhost.local
      ......
</VirtualHost>

<VirtualHost *:9010>
      ServerName site2.localhost.local
      ......
 </VirtualHost>

In your examples you are using subdirectory as you servername and this is not work, that seems to be the issue

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM