与 ProxyPass 一起使用时,Apache 别名被忽略

与 ProxyPass 一起使用时,Apache 别名被忽略

我正在尝试安装约特在我的服务器上,我想使用 apache 而不是 nginx。安装指南仅列出一个 nginx 配置文件,我正在尝试“翻译”它。

配置是三个不同的代理路由,第一个通向docker容器,第二个(/静止的/) 到一个包含样式表和类似内容的目录,最后一个到一个 unix 域套接字。

就我而言,第一条路线似乎有效(我可以访问该站点),但对静态资源的每个请求都会返回 404。看起来每个请求都使用了 docker ProxyPass 指令(无论顺序如何:如果我把它放在最后(见下文),它仍然是唯一使用的)。

这是创建的日志文件(的一部分):

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

这可能是什么原因呢?

这是 nginx 配置:

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 "";
    }
}

以下是我目前所得到的:

<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>

或者

<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>

答案1

您需要使用以下方法从代理中排除静态数据!

ProxyPass "/static" "!"

这应该出现在配置中的代理命令之前。

或者:

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

也可以看看ProxyPass 官方文档

相关内容