與 ProxyPass 一起使用時 Apache 別名會被忽略

與 ProxyPass 一起使用時 Apache 別名會被忽略

我正在嘗試安裝約特在我的伺服器上,我想使用 apache 而不是 nginx。這安裝指南只列出了一個 nginx 設定文件,我正在嘗試「翻譯」它。

配置是三個不同的代理路由,第一個通往 docker 容器,第二個(/靜止的/) 到一個包含樣式表和類似內容的目錄,最後一個到 unix 域套接字。

就我而言,第一個路由似乎有效(我可以訪問該站點),但對靜態資源的每個請求都會返回404。指令)最後(見下文),它仍然是唯一使用的)。

這是已建立的日誌檔案(的一部分):

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 官方文檔

相關內容