![无法加载静态资源,这个 Nginx 设置有什么问题?](https://linux22.com/image/695298/%E6%97%A0%E6%B3%95%E5%8A%A0%E8%BD%BD%E9%9D%99%E6%80%81%E8%B5%84%E6%BA%90%EF%BC%8C%E8%BF%99%E4%B8%AA%20Nginx%20%E8%AE%BE%E7%BD%AE%E6%9C%89%E4%BB%80%E4%B9%88%E9%97%AE%E9%A2%98%EF%BC%9F.png)
在运行 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" />
答案1
您的应用程序已经开发完毕,因此您的文档根目录必须是:
根/数据/www/demos/jqgrid;
然后你就可以通过 URL 访问应用程序了http://www.example.com/demos/jqgrid
。为什么会这样开发,你得问问做这件事的人。