AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 820989
Accepted
ReynierPM
ReynierPM
Asked: 2016-12-16 12:00:43 +0800 CST2016-12-16 12:00:43 +0800 CST 2016-12-16 12:00:43 +0800 CST

静态资源无法加载,这个 Nginx 设置有什么问题?

  • 772

在运行 PHP71-FPM 和 Nginx 的 Docker 容器中,我对 Nginx 进行了以下设置:

server {
    listen      80  default_server;
    listen      81  default_server http2 proxy_protocol; ## Needed when behind HAProxy with SSL termination + HTTP/2 support
    listen      443 default_server ssl http2;

    ssl_certificate       /etc/nginx/ssl/dummy.crt;
    ssl_certificate_key   /etc/nginx/ssl/dummy.key;

    root        /data/www/demos/jqgrid;
    index       index.php index.html index.htm;

    location ~ \.php$ {
      include         fastcgi_params;
      fastcgi_pass    php-upstream;
    }

    include     /etc/nginx/conf.d/stub-status.conf;
    include     /etc/nginx/conf.d/default-*.conf;
}

访问http://localhost会显示index页面,但没有加载样式或任何 JS 文件。我无法找到阻止访问静态文件的原因。

这是主机中命令的输出ls -la(请记住,这是一个运行 PHP-FPM 和 Nginx 的 Docker 容器):

$ ls -la ~/dev/
total 96
drwxrwxr-x  11     80     80 4096 Dec 15 14:36 .
drwx------. 40 rperez rperez 4096 Dec 15 15:01 ..
drwxr-xr-x   5     80     80 4096 Mar 13  2015 css
drwxr-xr-x   7     80     80 4096 Aug  5  2015 demos
drwxr-xr-x   6     80     80 4096 Mar 26  2015 js
drwxr-xr-x   2     80     80 4096 Mar 27  2015 northwindSQL
drwxr-xr-x   4     80     80 4096 Mar 16  2015 php

权限来自 Docker(对我来说很奇怪,但我在这里打开了另一篇文章)

这些文件来自我的存储库,而这些FROM文件来自Dockerfile中的存储库。

我能得到一些帮助吗?

更新

正如@Michael 建议的那样,我检查了容器上的 Nginx 日志,我可以看到以下内容:

php71-fpm-nginx | 2016-12-15 20:02:40,483 DEBG 'nginx' stderr output:
php71-fpm-nginx | 2016/12/15 20:02:40 [error] 33#33: *46 open() "/data/www/demos/jqgrid/css/jquery-ui.css" failed (2: No such file or directory), client: 172.20.0.1, server: , request: "GET /css/jquery-ui.css HTTP/1.1", host: "localhost:8080", referrer: "http://localhost:8080/index.php"
php71-fpm-nginx | 
php71-fpm-nginx | 2016-12-15 20:02:40,830 DEBG 'nginx' stderr output:
php71-fpm-nginx | 2016/12/15 20:02:40 [error] 33#33: *46 open() "/data/www/demos/jqgrid/css/control_icon.png" failed (2: No such file or directory), client: 172.20.0.1, server: , request: "GET /css/control_icon.png HTTP/1.1", host: "localhost:8080", referrer: "http://localhost:8080/index.php"
php71-fpm-nginx | 

但是,如果代码相反,这怎么可能呢?

<script src="../../js/jquery.min.js" type="text/javascript"></script>
<script src="../../js/jquery-ui.min.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="../../css/jquery-ui.css" media="screen" />
nginx static-content centos7
  • 1 1 个回答
  • 81 Views

1 个回答

  • Voted
  1. Best Answer
    Tero Kilkanen
    2016-12-16T12:38:49+08:002016-12-16T12:38:49+08:00

    您的应用程序已经开发,因此您的文档根必须是:

    根 /data/www/demos/jqgrid;

    然后您将使用 URL 访问应用程序http://www.example.com/demos/jqgrid。为什么会发展成这样,你得问问做它的人。

    • 0

相关问题

  • Gzip 与反向代理缓存

  • nginx 作为代理的行为

  • Nginx 学习资源 [关闭]

  • 提供 70,000 个静态文件 (jpg) 的最佳方式?

  • 在 Apache、LightTPD 和 Nginx Web 服务器上提供 PHP 5.x 应用程序的现状?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve