php - 带有 PHP Nginx 的 Docker 无法加载图像或 js - 找不到 404
问题描述
我在我的 windows 10 pro 本地机器上部署了 2 个 docker 容器(nginx 和 php fpm)。
我可以正确执行 php 脚本。
例如:http://localhost:8888/phpinfo.php --> 这个返回正确。
但除了 php 脚本(例如图像、js 或 css)之外,它给了我没有找到。
例如:http://localhost:8888/image.jpg --> 未找到
这里可能出了什么问题?
这是我的码头工人撰写文件:
version: '3.7'
services:
# The Web Server
web:
container_name: emm_web
build:
context: ./
dockerfile: web.dockerfile
volumes:
- ../log/:/var/log
ports:
- 8888:80
# The PHP Application
app:
container_name: emm_app
build:
context: ./
dockerfile: app.dockerfile
volumes:
- ../www/:/var/www
depends_on:
- web
environment:
- "DB_PORT=3306"
- "DB_HOST=database"
这是我的 nginx vhost.conf:
server {
listen 80;
index index.php index.html;
root /var/www;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
location / {
try_files $uri /index.php?$args;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass app:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
谢谢 :)
解决方案
您需要为 nginx 容器共享文件。尝试这个:
# The Web Server
web:
container_name: emm_web
build:
context: ./
dockerfile: web.dockerfile
volumes:
- ../log/:/var/log
# !! nginx need this volume !!
- ../www/:/var/www:ro
ports:
- 8888:80
该只读卷将使容器中的文件可用。
推荐阅读
- angular - 自定义错误处理 Angular:抛出特定错误
- c# - WCF:无法使用安全绑定导入 WSDL
- scala - 用地图值替换自定义对象列表中的值
- image - 如何将 Reality Composer (RealityKit) 场景锚定到检测到的图像
- javascript - db.getConnection 不是函数
- python - 基于过滤器的列计算?
- ruby-on-rails - nativescript 使用 angular-token 导致 localStorage 错误
- r - 如何读取缩进的数据?
- python - 压缩序列化 Python 数据最节省空间的方法是什么?
- c# - MsiQueryProductState 如何判断 VC++ 是否安装