如何在Nginx上渲染Sails css和js文件
How to render Sails css and js files on Nginx
我在Nginx上运行我的Sails应用程序,但它既不渲染我的CSS文件,也不监听我的JS文件。
My nginx/sites-available/mywebpage.conf:
listen 80;
server_name myservername.com;
root /path/to/page;
location / {
proxy_pass http://localhost:1337;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location ~* '.(img|js|css)$ {
root /assets;
expires 7d;
access_log off;
}
这是我的帆布局:
<!--STYLES-->
<link rel="stylesheet" href="/styles/bootstrap-theme.css">
<link rel="stylesheet" href="/styles/bootstrap.css">
<link rel="stylesheet" href="/styles/importer.css">
<link rel="stylesheet" href="/styles/style.css">
<!--STYLES END-->
<!--SCRIPTS-->
<script src="/js/dependencies/sails.io.js"></script>
<script src="/js/jquery-1.11.3.min.js"></script>
<!--SCRIPTS END-->
Nginx 日志:
2016/01/28 14:50:41 [error] 8319#0: *7 open() "myservername/styles/bootstrap.css" failed (2: No such file or directory), client: 127.0.0.1, server: myservername.com, request: "GET /path/to/page/styles/bootstrap.css HTTP/1.1", host: "myservername.com", referrer: "http://myservername.com/sailsroute"
此错误随每个 CSS 和 JS 文件一起显示。
有人知道如何渲染这样的文件吗?
提前感谢!
我有帆船应用程序在Nginx上成功运行,
在我的启用 Nginx 站点的配置中,我有:
# Load balancer configuration
upstream example.com {
# Directs to the process with least number of connections.
least_conn;
`enter code here`# One failed response will take a server out of circulation for 20 seconds.
server 127.0.0.1:10080 fail_timeout=20s;
server 127.0.0.1:10081 fail_timeout=20s;
server 127.0.0.1:10082 fail_timeout=20s;
server 127.0.0.1:10083 fail_timeout=20s;
keepalive 64;
}
# WebSocket "upgrade" method
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
# Server settings
server {
(...)
#Set server root
root /usr/share/nginx/html/example.com/.tmp/public;
(...)
# pass the request to the node.js server with the correct headers
location / {
# Setting proxy headers
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;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
#Set proxy
proxy_pass http://example.com;
proxy_redirect off;
proxy_http_version 1.1;
# WebSocket headers
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
(...)
}
(...)
此配置似乎工作正常。
我希望我以某种方式有所帮助。
再见
相关文章:
- CSS-如何定位内容数据标题
- 窗口大小html css
- 如果文本字段为空,则使用JavaScript应用CSS样式
- 动画.CSS重播
- 有没有一种方法可以防止img get请求使用css或js发生
- Sails.js:同时发布文本输入和一个文件
- CSS表格:从列平移到整个表格宽度
- CKEditor-我在editor.css中的风格是't
- 单击更改图标并通过javascript添加一个css类
- 将CSS应用于printWindow.print();在Javascript中
- 使用CSS或js,使用动态选择器选择任意li的下一个元素
- CSS-若窗口太小,滚动条会出现在“表格”单元格上
- css(或jQuery)悬停时淡入淡出
- 为什么不'在JQuery中找到第二个css选择器的工作
- 为什么 .focus() 不起作用,而 .css(“color”,“red”) 在同一个选择器上起作用
- 如何在Nginx上渲染Sails css和js文件
- 如何使我的 sails 应用程序在 dev 中使用本地 js 和 css 依赖项,并在生产中使用 cdn
- 如何在Sails.js0.11中添加自定义CSS和JS文件
- 如何在sails应用程序中为CSS生成地图文件
- 如何在sails.js中使用gruntfile.js来最小化所有的js和css文件