【发布时间】:2015-01-30 18:35:01
【问题描述】:
由于某些限制,我需要从子目录(例如 hostname.domain.com/mysailsapp)托管我的应用程序。网络服务器是 nginx 并设置为到sails/node 的代理连接。
我面临的问题是 grunt 会自动构建链接以包含前端 javascript/css/images/etc,但整个sails 应用程序预计处于根级别。
当我通过端口 1337 直接连接到sails 时,一切正常,因为sails 位于根目录,但是当通过代理到sails 的子目录URL 连接时,这将不起作用。
我没有看到配置sails 来改变这种行为的简单方法,并且不想手动更新grunt 构建路径。
也许我还遗漏了其他东西,但想在 SO 上打开它,看看是否有其他方法,或者我是否应该打开一个问题,让风帆包含这样的配置选项。
编辑: 通过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 代理 http://host1.domain.com/mysailsapp/ 托管sails 应用程序,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
由于浏览器试图在子目录之外加载静态资源,因此此链接将不起作用。
【问题讨论】:
标签: sails.js