我正在使用以下设置使用Docker Compose创建一个laravel项目:
docker-compose.yml
version: '2'
services:
app:
build:
context: ./
dockerfile: app.dockerfile
working_dir: /var/www
volumes:
- ./:/var/www
environment:
- "DB_PORT=3306"
- "DB_HOST=database"
web:
build:
context: ./
dockerfile: web.dockerfile
working_dir: /var/www
volumes_from:
- app
ports:
- 8001:80
database:
image: mysql:5.7
volumes:
- dbdata:/var/lib/mysql
environment:
- "MYSQL_DATABASE=xxxx"
- "MYSQL_USER=xxxx"
- "MYSQL_PASSWORD=xxxx"
- "MYSQL_ROOT_PASSWORD=xxxx"
ports:
- 33061:3306
volumes:
dbdata:
nginx.conf
events {
worker_connections 2048;
}
http {
server {
listen 80;
index index.php index.html;
root /var/www;
location / {
try_files $uri /index.php?$args;
}
location ~ \.css {
add_header Content-Type text/css;
}
location ~ \.js {
add_header Content-Type application/x-javascript;
}
location ~ ^/(assets/|css/|js/|index.html) {
root /var/www;
index index.html;
access_log off;
}
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;
}
}
}
web.dockerfile
FROM nginx:alpine
RUN apk --update add supervisor
RUN addgroup -g 1000 -S www-data \
&& adduser -u 1000 -D -S -G www-data www-data
RUN rm /var/cache/apk/*
COPY nginx.conf /etc/nginx/nginx.conf
COPY supervisord-web.conf /etc/supervisord.conf
ENTRYPOINT ["/usr/bin/supervisord", "-n", "-c", "/etc/supervisord.conf"]
运行$:docker-compose up可以正常工作,但是当我进入http://localhost:8001时,出现以下错误:
app_1 | 172.23.0.4 - 04/Sep/2018:13:06:29 +0000 "GET /index.php" 404
web_1 | 2018/09/04 13:06:29 [error] 9#9: *4 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.23.0.1, server: , request: "GET / HTTP/1.1", upstream: "fastcgi://172.23.0.2:9000", host: "localhost:8001"
web_1 | 172.23.0.1 - - [04/Sep/2018:13:06:29 +0000] "GET / HTTP/1.1" 404 27 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36"
web_1 | 2018/09/04 13:06:31 [error] 9#9: *4 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.23.0.1, server: , request: "GET / HTTP/1.1", upstream: "fastcgi://172.23.0.2:9000", host: "localhost:8001"
web_1 | 172.23.0.1 - - [04/Sep/2018:13:06:31 +0000] "GET / HTTP/1.1" 404 27 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36"
app_1 | 172.23.0.4 - 04/Sep/2018:13:06:31 +0000 "GET /index.php" 404
起初,我认为我的默认“ public_html”文件夹是错误的,但我认为它与working_dir(在应用程序服务下)和nginx.conf匹配
我不确定我在这里想念的是什么,希望我能在这里得到答案。谢谢您的帮助。