2

I want to map these domains to these ports. How can I do it?

http://test1.example.com/phpmyadmin/    example.com:80/phpmyadmin/
http://test1.example.com/app1/          example.com:8080/app1/
http://test1.example.com/app2/          example.com:8090/app2/

http://webmin.example.com/              example.com:10000/

This is what I did. The problem is, phpmyadmin is not working. It is forwarded to glassfish.

webmin is working because it is a seperate domain.

How can I map phpmyadmin to the same domain? http://test1.example.com/phpmyadmin/

<VirtualHost *:80>
    ServerName              test1.example.com
    ProxyRequests           Off
    ProxyPreserveHost       On

    <Proxy *>
      Order deny,allow
      Allow from all
    </Proxy>

    ProxyPass           /           http://localhost:8080/
    ProxyPassReverse    /           http://localhost:8080/

    ProxyPass           /admin/     https://localhost:4848/
    ProxyPassReverse    /admin/     https://localhost:4848/
</VirtualHost>

<VirtualHost *:80>
    ServerName      test1.example.com/phpmyadmin/
    DocumentRoot    /usr/share/phpmyadmin

    Alias           /phpmyadmin     /usr/share/phpmyadmin
    Alias           /mysql          /usr/share/phpmyadmin
</VirtualHost>

<VirtualHost *:80>
    ServerName              webmin.example.com
    ProxyRequests           Off
    ProxyPreserveHost       On

    <Proxy *>
      Order deny,allow
      Allow from all
    </Proxy>

    ProxyPass           /               http://localhost:10000/
    ProxyPassReverse    /               http://localhost:10000/
</VirtualHost>
2

Put the new locations inside the top VirtualHost block:

<VirtualHost *:80>
    ServerName              test1.example.com
    ProxyRequests           Off
    ProxyPreserveHost       On

    <Proxy *>
    Order deny,allow
    Allow from all
    </Proxy>

    ProxyPass           /           http://localhost:8080/
    ProxyPassReverse    /           http://localhost:8080/

    ProxyPass           /admin/     https://localhost:4848/
    ProxyPassReverse    /admin/     https://localhost:4848/

    ProxyPass           /phpmyadmin/     https://localhost:80/phpmyadmin/
    ProxyPassReverse    /phpmyadmin/     https://localhost:80/phpmyadmin/

    ProxyPass           /app1/     https://localhost:8080/app1/
    ProxyPassReverse    /app1/     https://localhost:8080/app1/

    ProxyPass           /app2/     https://localhost:8090/app2/
    ProxyPassReverse    /app2/     https://localhost:8090/app2/
</VirtualHost>
1

As @josh-jolly suggests… placing the various proxy statements into a single VHost is helpful given that your configuration has multiple VHosts all listening for absolutely anything on port 80.

BASIC ORDER OF COMPLEXITY

However, what Josh's recommendation doesn't communicate (and incorrectly illustrates in his example) is that mod_proxy, like mod_rewrite, processes the patterns provided in the order they are received.

What this means is that if you place the following lines before the other ProxyPass/ProxyPassReverse blocks that all traffic will get caught by this pattern.

ProxyPass           /           http://localhost:8080/
ProxyPassReverse    /           http://localhost:8080/

This is likely why all traffic was being sent to Glassfish instead of your desired traffic making it to PHPMyAdmin.

NESTED ORDER OF COMPLEXITY

Likewise, you should be careful with order of complexity rules on URL patterns you wish you route differently but which are nested.

The following example shows a poorly crafted order of complexity rule set.

ProxyPass           /myapp          http://localhost:9090/
ProxyPassReverse    /myapp          http://localhost:9090/

ProxyPass           /myapp/images   http://localhost:8080/
ProxyPassReverse    /myapp/images   http://localhost:8080/

In this example, all traffic would flow to the 9090 port because both urls contact /myapp but mod_proxy matched the more basic pattern before it could get to the /myapp/images pattern.

Ordering the blocks like the following will allow both patterns to be matched appropriately because of the decreasing level of complexity in the URL patterns.

ProxyPass           /myapp/images   http://localhost:8080/
ProxyPassReverse    /myapp/images   http://localhost:8080/

ProxyPass           /myapp          http://localhost:9090/
ProxyPassReverse    /myapp          http://localhost:9090/

GOOD HABITS

  1. Include comments in your VHost configurations. You will not always be the person updating or managing them.
  2. ProxyPass and ProxyPassReverse should always match. I have never found a valid use where the two directives should differ. This is especially true with including or not including a trailing slash on the URL pattern.
  3. Group related directives together and separate them visually with some kind of comment block. This is especially useful for large or complex VHost configurations. But when practices as a habit will make your life much easier.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.