Caprover nginx主机mjs文件

gfttwv5a  于 2023-03-29  发布在  Nginx
关注(0)|答案(1)|浏览(349)

我有一个包含nginx代码的capover应用程序:

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

        location / {

    <%
    if (s.httpBasicAuthPath) {
    %>
            auth_basic           "Restricted Access";
            auth_basic_user_file <%-s.httpBasicAuthPath%>; 
    <%
    }
    %>

            proxy_pass $upstream;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;

    <%
    if (s.websocketSupport) {
    %>
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_http_version 1.1;
    <%
    }
    %>
        }

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

我想用.mjs文件托管我的故事书静态构建index.html看起来像:

<script type="module">
      import './sb-manager/runtime.mjs';

      
      import './sb-addons/links-0/manager-bundle.mjs';
      
      import './sb-addons/essentials-controls-1/manager-bundle.mjs';
      
      import './sb-addons/essentials-actions-2/manager-bundle.mjs';
      
      import './sb-addons/essentials-backgrounds-3/manager-bundle.mjs';
      
      import './sb-addons/essentials-viewport-4/manager-bundle.mjs';
      
      import './sb-addons/essentials-toolbars-5/manager-bundle.mjs';
      
      import './sb-addons/essentials-measure-6/manager-bundle.mjs';
      
      import './sb-addons/essentials-outline-7/manager-bundle.mjs';
      
      import './sb-addons/interactions-8/manager-bundle.mjs';
      
    </script>

但我得到错误:nginx无法加载模块脚本:应为JavaScript模块脚本,但服务器响应的MIME类型为“application/octet-stream”。根据HTML规范,对模块脚本强制执行严格的MIME类型检查。
我需要一些关于nginx配置的帮助。我试图添加include /etc/nginx/mime.types;但没有别的。

wvmv3b1j

wvmv3b1j1#

问题出在Nginx服务器上。2 mime类型扩展'mjs'是未知的,并且nginx使用默认的mime类型'application/octet'。3 Npx知道关系Map,所以没有问题。
更新'includemime.types'下的server部分中的nginx.conf文件;'以包含新类型。

include mime.types;
types {
   application/javascript js mjs;
}

相关问题