Apache – Alias Ignored When Used with ProxyPass

apache-2.4nginxreverse-proxyvirtualhost

I'm trying to install yotter on my server, and I want to use apache instead of nginx. The installation guide only lists an nginx configuration file, which I'm trying to "translate".

The config is three different proxy routes, the first one leading to a docker container, the second one (/static/) to a directory with stylesheets and stuff like that and the last one to a unix domain socket.

In my case, the first route seems to work (I can access the site), but each request to a static ressource returns a 404. It looks like each requests uses the docker ProxyPass directive (no matter the order: if I put that one last (see below), it's still the only one used).

This is (a part of) the log file created:

yotter.domain.tld - - [12/Aug/2021:21:14:21 +0200] "GET /static/favicons/favicon.ico HTTP/1.1" 404 1935 file=proxy:http://127.0.0.1:5000/static/favicons/favicon.ico
yotter.domain.tld - - [12/Aug/2021:21:15:54 +0200] "GET /index HTTP/1.1" 200 1126 file=proxy:http://127.0.0.1:5000/index
yotter.domain.tld - - [12/Aug/2021:21:15:54 +0200] "GET /static/semantic/semantic.min.css HTTP/1.1" 404 1935 file=proxy:http://127.0.0.1:5000/static/semantic/semantic.min.css

What could be the reason for this?

This is the nginx config:

server {
    listen 80;
    server_name <example.com>; # ChangeME
    access_log off;

    location / {
        proxy_pass http://127.0.0.1:5000;
        proxy_http_version 1.1;
        proxy_set_header Connection "";
    }

    location /static/ {
        root /home/ubuntu/Yotter/app/; # Change this depending on where you clone Yotter
        sendfile on;
        aio threads=default;
    }

    location ~ (^/videoplayback$|/videoplayback/|/vi/|/a/) {
        proxy_pass http://unix:/var/run/ytproxy/http-proxy.sock;
        add_header Access-Control-Allow-Origin *;
        sendfile on;
        tcp_nopush on;
        aio_write on;
        aio threads=default;
        directio 512;
        proxy_http_version 1.1;
        proxy_set_header Connection "";
    }
}

And here is what I have so far:

<VirtualHost *:443>
        ServerName yotter.domain.tld

        LogFormat "%v %l %u %t \"%r\" %>s %b file=%f" commonvhost
        CustomLog ${APACHE_LOG_DIR}/yotter_access.log commonvhost

        SSLEngine on
        SSLCertificateFile /etc/letsencrypt/live/domain.tld/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/domain.tld/privkey.pem

        <Location "/">
                ProxyPass http://127.0.0.1:5000/
                ProxyPassReverse http://127.0.0.1:5000/
        </Location>


        <Location "/static">
                Alias "/var/www/Yotter/app/static"
        </Location>

        <Directory "/var/www/Yotter/app/">
                Require all granted
        </Directory>


        <LocationMatch (^/videoplayback$|/videoplayback/|/vi/|/a/)>
                ProxyPass unix:///var/run/ytproxy/http-proxy.sock
                ProxyPassReverse unix:///var/run/ytproxy/http-proxy.sock
                Header add Acces-Control-Allow-Origin: *
        </LocationMatch>

</VirtualHost>

or

<VirtualHost *:443>
        ServerName yotter.domain.tld

        LogFormat "%v %l %u %t \"%r\" %>s %b file=%f" commonvhost
        CustomLog ${APACHE_LOG_DIR}/yotter_access.log commonvhost

        SSLEngine on
        SSLCertificateFile /etc/letsencrypt/live/domain.tld/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/domain.tld/privkey.pem


        Alias "/static" "/var/www/Yotter/app/static"

        <Directory "/var/www/Yotter/app/">
                Require all granted
        </Directory>


        <LocationMatch (^/videoplayback$|/videoplayback/|/vi/|/a/)>
                ProxyPass unix:///var/run/ytproxy/http-proxy.sock
                ProxyPassReverse unix:///var/run/ytproxy/http-proxy.sock
                Header add Acces-Control-Allow-Origin: *
        </LocationMatch>


        ProxyPass / http://127.0.0.1:5000/
        ProxyPassReverse / http://127.0.0.1:5000/

</VirtualHost>

Best Answer

You need to exclude statics from proxying with !:

ProxyPass "/static" "!"

This should appear before the proxy commands in the config.

Or:

<Location "/static">
    ProxyPass "!"
</Location>

See also ProxyPass official documentation.

Related Topic