【问题标题】:CapRover serving static files from hostCapRover 从主机提供静态文件
【发布时间】:2021-10-03 14:13:46
【问题描述】:

我想使用 CapRover 提供位于主机服务器上的静态文件。

我做了什么:

  1. 已创建目录结构/srv/foo/bar
  2. 确保bar 权限为drw-rw-r--,其中所有文件均为-rw-r--r--
  3. 在 CapRover 仪表板中创建了名为 app 的新应用。
  4. 修改了其 Nginx 配置(一直向下滚动以查看我的更改):
<%
if (s.forceSsl) {
%>
    server {
        listen       80;
        server_name  <%-s.publicDomain%>;

        # Used by Lets Encrypt
        location /.well-known/acme-challenge/ {
            root <%-s.staticWebRoot%>;
        }

        # Used by CapRover for health check
        location /.well-known/captain-identifier {
            root <%-s.staticWebRoot%>;
        }

        location / {
            return 302 https://$http_host$request_uri;
        }
    }
<%
}
%>

server {
    <%
    if (!s.forceSsl) {
    %>
        listen       80;
    <%
    }
    if (s.hasSsl) {
    %>
        listen              443 ssl http2;
        ssl_certificate     <%-s.crtPath%>;
        ssl_certificate_key <%-s.keyPath%>;
    <%
    }
    %>

        client_max_body_size 500m;
        server_name  <%-s.publicDomain%>;

        # 127.0.0.11 is DNS set up by Docker, see:
        # https://docs.docker.com/engine/userguide/networking/configure-dns/
        # https://github.com/moby/moby/issues/20026
        resolver 127.0.0.11 valid=10s;
        # IMPORTANT!! If you are here from an old thread to set a custom port, you do not need to modify this port manually here!!
        # Simply change the Container HTTP Port from the dashboard HTTP panel
        set $upstream http://<%-s.localDomain%>:<%-s.containerHttpPort%>;

        # THIS IS WHAT I CHANGED
        location / {
            root /srv/foo/bar;
        }

        # Used by Lets Encrypt
        location /.well-known/acme-challenge/ {
            root <%-s.staticWebRoot%>;
        }
        
        # Used by CapRover for health check
        location /.well-known/captain-identifier {
            root <%-s.staticWebRoot%>;
        }

        error_page 502 /captain_502_custom_error_page.html;
        location = /captain_502_custom_error_page.html {
                root <%-s.customErrorPagesDirectory%>;
                internal;
        }
}
  1. 我什至为应用设置了持久目录映射,/srv/foo/srv/foo

但是当我从浏览器打开https://app.caprover.mydomain.com/test.jpg 时:

404 Not Found
nginx

于是我查看了 Nginx 日志 (docker service logs captain-nginx --follow):

... *4773 open() "/srv/foo/bar/test.jpg" failed (2: No such file or directory), client: 1.2.3.4, server: app.caprover.mydomain.com, request: "GET /test.jpg HTTP/1.1", host: "app.caprover.mydomain.com"
... "app.caprover.mydomain.com" "GET /test.jpg HTTP/1.1" 404 548 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64)" "-"

我错过了什么?

【问题讨论】:

  • test.jpg文件在文件结构中的位置?

标签: nginx caprover


【解决方案1】:

Nginx 正在容器内部寻找 /srv/foo/bar 的路径 我已经在 caprover nginx 容器之外创建了目录,然后必须将它映射到容器中以使 nginx 能够访问它。

【讨论】:

    猜你喜欢
    • 2013-08-22
    • 2013-05-28
    • 2012-02-11
    • 1970-01-01
    • 1970-01-01
    • 2021-06-14
    • 1970-01-01
    • 2018-07-26
    • 1970-01-01
    相关资源
    最近更新 更多