简体   繁体   中英

Apache proxying subdomain root requests

Description

  • Internal Tomcat server that has webapps listening on 8080:

    "http://internal:8080/foo-webservice/"
    "http://internal:8080/foo-website/"

  • External facing Apache server is proxying requests for a subdomain:

    "http://foo.domain.com/"

  • Any requests of the root of the subdomain would be proxied to the foo-website webapp on Tomcat.

  • Any other requests would be proxied to the appropriate path / webapp

Use Case A

  • Request:
    "http://foo.domain.com/index.html"

  • Proxied to:
    "http://internal:8080/foo-website/index.html"

Use Case B

  • Request:
    "http://foo.domain.com/webservice/listener.html?param1=foo&param2=bar"

  • Proxied to:
    "http://internal:8080/foo-webservice/listener.html?param1=foo&param2=bar"

VirtualHost definition

  • Current virtual host definition which satisfies Use Case B:

     <VirtualHost *:80> ServerName foo.domain.com ProxyRequests Off <Proxy *> Order deny,allow Allow from all </Proxy> ErrorLog /var/log/apache2/foo_error.log LogLevel warn CustomLog /var/log/apache2/foo_access.log combined # RewriteRules # ? # ProxyPass ProxyPreserveHost On ProxyPass / http://internal:8080/ ProxyPassReverse / http://internal:8080/ </VirtualHost> 

Attempt 1

    # RewriteRules
    RewriteEngine On
    RewriteRule ^/(.*) http://internal:8080/foo-website/$1 [P]
  • Use Case A is satisfied
  • Use Case B fails

Attempt 2

    # RewriteRules
    RewriteEngine On
    RewriteRule ^/$ http://internal:8080/foo-website/$1 [P]
  • Use Case B is satisfied
  • Use Case A is not completely satisfied
  • The index.html in foo-website is loaded, but none of the files in the js, img or css folders.

ProxyPass rules match in order

 ProxyPass        /webservice/ http://internal:8080/foo-webservice/
 ProxyPassReverse /webservice/ http://internal:8080/foo-webservice/

 ProxyPass        /website/ http://internal:8080/foo-website/
 ProxyPassReverse /website/ http://internal:8080/foo-website/

 ProxyPass        / http://internal:8080/foo-website/
 ProxyPassReverse / http://internal:8080/foo-website/

No rewrite rule. Isn't that good enough ?

我认为您需要使用第一次尝试,但要在每个RewriteRule指令末尾的方括号中包含QSA(查询字符串追加)标志。

  • I think the issue with Attempt 2 (none of the files in the js, img or css folders being mapped) was a sign that my approach was wrong.

  • My solution now is to redirect any requests to the root, to the foo-website webapp.

      <VirtualHost *:80> ServerName foo.domain.com ProxyRequests Off <Proxy *> Order deny,allow Allow from all </Proxy> ErrorLog /var/log/apache2/foo_error.log LogLevel warn CustomLog /var/log/apache2/foo_access.log combined # RewriteRules RewriteEngine On RewriteRule ^/$ /foo-website/ [R] # ProxyPass ProxyPreserveHost On ProxyPass / http://internal:8080/ ProxyPassReverse / http://internal:8080/ </VirtualHost> 
  • This was not what I originally wanted, but I think this is the resolution.

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