【发布时间】:2017-02-04 22:36:51
【问题描述】:
我已经阅读了一些文档,并尝试了本网站上以前答案的替代方案,但无法让 nginx 从我的烧瓶应用程序中提供我的 css 和 js 文件。在我的代码中,例如:
<link rel="stylesheet" href="{{ url_for('static', filename='css/main.css') }}"/>
<script type="text/javascript" src=" ../static/js/jquery.tablesorter.js"></script>
在我的 nginx 配置“/etc/nginx/sites-enabled/src”中,我能够获取模板中的 html 文件以正常提供服务,还能够获取静态文件夹中的“log_big.png”文件以提供服务好的...但我无法让第三个位置条目工作并提供这些嵌套文件:
server {
location / {
proxy_pass http://localhost:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
location /templates {
alias /home/www/src/templates/; # This works ok for html files
}
location /static/ {
alias /home/www/src/static/; # This works ok for the .png file
}
location /CSS/ {
autoindex on;
root /home/www/src/static/; # This doesn't work ?
}
include /etc/nginx/mime.types;
}
谁能告诉我我做错了什么?
【问题讨论】:
-
你检查过
nginx-access.log和nginx-error.log吗?我注意到您使用了不一致的大小写,您的实现是否忽略大小写? -
您接受了 CGI 请求,但您想使用 flask/nginx/etc 推送静态文件?您不能两次处理硬件缓冲区,任何读取/接受命令都将被清除硬件缓冲区。
-
您不仅混合大小写(
CSS与css),还在 JavaScript 路径中包含../static/。删除它。 -
@dim,您的建议通过按照建议修改代码中的指针为我修复了...非常愚蠢的错误,但谢谢:) 如果您想添加作为答案,我将标记为答案.
标签: python nginx flask gunicorn nginx-location