How to redirect a name-based VirtualHost to a different port

apache-2.2endpointvirtualhost

I have a virtuoso sparql endpoint installed, which I want to make available through a hostname (e.g. www.virtuosoexample.com). The thing with virtuoso is that the is no Document root. The endpoint is initiated by the daemon and made available through a source port (e.g. localhost:1234/)

I know how to set a virtual host pointing to a document root, but i don't know how to do this for a server with a port number.

Any advice would be appreciated.

Below is the code, how I would do it with a document root.

I tried to change that (naively) into localhost:1234/sparql, but that didn't work

<VirtualHost *>

   ServerName www.virtuosoexample.com <www.virtuosoexample.com> 
    ServerAlias www.virtuosoexample.com <www.virtuosoexample.com> 

    ErrorLog /var/log/apache2/error.wp-sparql.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog /var/log/apache2/access.wp-sparql.log combined


    DocumentRoot /var/www/endpoint/sparql/
    <Directory /var/www/endpoint/sparql>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
    </Directory> 

</VirtualHost>

Best Answer

You would not do this by mucking with Apache's DocumentRoot. Instead, you would use mod_proxy and set up Apache as a reverse proxy.

You would add something like:

ProxyPass / http://localhost:1234/sparql
ProxyPassReverse / http://localhost:1234/sparql

to your configuration. Make sure mod_proxy is loaded by Apache.

Here is the official documentation.