Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to achieve an apache Alias with a proxy pass on the same domain

We have a NodeJS site running with an Apache VirtualHost that looks like this:

<VirtualHost *:80>
    ServerName      domain.org
    ServerAlias www.domain.org

    ProxyPass / http://localhost:8884/
    ProxyPassReverse / http://localhost:8884/

    ProxyPreserveHost on

    LogLevel debug
</VirtualHost>

This works fine.

however we have now been tasked with installing a wordpress blog as an alias of the domain

www.domain.org/blog

To do this we tried setting up a vhost with an Alias like this:

<VirtualHost *:80>
       Alias /blog /var/apache-vhosts/www.domain.org-blog

       <Directory /var/apache-vhosts/www.domain.org-blog/>
           Options Indexes FollowSymLinks MultiViews
           AllowOverride All
           Order allow,deny
           allow from all
       </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

We have the mod_alias apache module enabled but it just wont pick it up.

Has anyone else achieved this?

I have also tried including the alias without a vhost wrapping tag but still no joy :/

like image 295
John Avatar asked Mar 19 '16 12:03

John


1 Answers

Note that ProxyPass has precedence over Alias.

To fix, declare another ProxyPass pointing to an exclamation mark (!).

For example:

<VirtualHost *:80>
    ServerName      domain.org
    ServerAlias www.domain.org
   
    # the next line is your fix
    ProxyPass /blog !
    Alias     /blog /var/apache-vhosts/www.domain.org-blog

    <Directory /var/apache-vhosts/www.domain.org-blog/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn
    CustomLog ${APACHE_LOG_DIR}/access.log combined


    ProxyPass        / http://localhost:8884/
    ProxyPassReverse / http://localhost:8884/
    ProxyPreserveHost on
    LogLevel debug
</VirtualHost>

You can find more information in the official ProxyPass documentation:

The ! directive is useful in situations where you don't want to reverse-proxy a subdirectory ― https://httpd.apache.org/docs/2.4/mod/mod_proxy.html

like image 161
wodka Avatar answered Nov 15 '22 04:11

wodka