gpt4 book ai didi

sails.js - 从子目录托管 sails.js 应用程序

转载 作者:行者123 更新时间:2023-12-02 04:52:03 26 4
gpt4 key购买 nike

由于某些限制,我需要从子目录(例如 hostname.domain.com/mysailsapp)托管我的应用程序。网络服务器是 nginx 并设置为代理连接到 sails/node。

我面临的问题是 grunt 自动在链接中构建以包含前端 javascript/css/images/etc,但整个 sails 应用程序预计处于根级别。

当我通过端口 1337 直接连接到 sails 时一切正常,因为 sails 位于根目录,但是当通过代理到 sails 的子目录 URL 连接时,这将不起作用。

我没有看到配置 sails 以更改此行为的简单方法,并且不想手动更新 grunt 构建路径。

也许我遗漏了其他东西,但想在 SO 上打开它以查看是否有其他方法,或者我是否应该为 sails 打开一个问题以包含这样的配置选项。

编辑:通过 http://host.domain.com:1337/ 访问,HTML 源代码包含如下链接:


<!--STYLES-->
<link rel="stylesheet" href="/bower_components/bootstrap/dist/css/bootstrap.css">
<link rel="stylesheet" href="/bower_components/bootstrap/dist/css/bootstrap-theme.css">
<link rel="stylesheet" href="/bower_components/font-awesome/css/font-awesome.css">
<!--STYLES END-->

这些链接工作正常,因为您可以从 sails/node 访问托管。 http://host.domain.com:1337/bower_components/bootstrap/dist/css/bootstrap.css - 返回 200

从 nginx 代理托管 sails 应用程序,http://host1.domain.com/mysailsapp/ ,sails/nginx 将此 HTML 返回给浏览器:


<!--STYLES-->
<link rel="stylesheet" href="/bower_components/bootstrap/dist/css/bootstrap.css">
<link rel="stylesheet" href="/bower_components/bootstrap/dist/css/bootstrap-theme.css">
<link rel="stylesheet" href="/bower_components/font-awesome/css/font-awesome.css">
<!--STYLES END-->

然后浏览器尝试通过以下方式加载静态资源: http://host1.domain.com/bower_components/bootstrap/dist/css/bootstrap.css

此链接将无效,因为浏览器正试图加载子目录之外的静态资源。

最佳答案

您可以将 nginx 配置为从该 url 提供静态内容。

location /mysailsapp/ {
alias /path/to/your/app/assets/;
}

关于sails.js - 从子目录托管 sails.js 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27250685/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com