在运行 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" />
您的应用程序已经开发,因此您的文档根必须是:
根 /data/www/demos/jqgrid;
然后您将使用 URL 访问应用程序
http://www.example.com/demos/jqgrid
。为什么会发展成这样,你得问问做它的人。