【问题标题】:Unable to serve the nested css & js files via nginx?无法通过 nginx 提供嵌套的 css 和 js 文件?
【发布时间】: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.lognginx-error.log吗?我注意到您使用了不一致的大小写,您的实现是否忽略大小写?
  • 您接受了 CGI 请求,但您想使用 flask/nginx/etc 推送静态文件?您不能两次处理硬件缓冲区,任何读取/接受命令都将被清除硬件缓冲区。
  • 您不仅混合大小写(CSScss),还在 JavaScript 路径中包含 ../static/。删除它。
  • @dim,您的建议通过按照建议修改代码中的指针为我修复了...非常愚蠢的错误,但谢谢:) 如果您想添加作为答案,我将标记为答案.

标签: python nginx flask gunicorn nginx-location


【解决方案1】:

您不仅混合大小写(CSScss),还在 JavaScript 路径中包含 ../static/。修正大写并删除../static/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-10
    • 1970-01-01
    • 2012-09-21
    • 2011-04-25
    • 1970-01-01
    • 2019-02-18
    • 2017-05-10
    • 2019-01-22
    相关资源
    最近更新 更多