使用nginx缺失片段/fastcgi-php.conf设置docker compose
我正在尝试设置一个新的docker compose文件使用nginx缺失片段/fastcgi-php.conf设置docker compose,docker,nginx,docker-compose,Docker,Nginx,Docker Compose,我正在尝试设置一个新的docker compose文件 version: '3' services: webserver: image: nginx:latest container_name: redux-webserver # working_dir: /application volumes: - ./www:/var/www/ - ./docker/nginx/site.conf:/etc/nginx/
version: '3'
services:
webserver:
image: nginx:latest
container_name: redux-webserver
# working_dir: /application
volumes:
- ./www:/var/www/
- ./docker/nginx/site.conf:/etc/nginx/conf.d/default.conf
ports:
- "7007:80"
目前它非常简单。但我复制了以下配置:
# Default server configuration
#
server {
listen 7007 default_server;
listen [::]:7007 default_server;
root /var/www;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name example;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/=404;
}
location /redux {
alias /var/www/Redux/src;
try_files $uri @redux;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
}
location @redux {
rewrite /redux/(.*)$ /redux/index.php?/$1 last;
}
# pass PHP scripts to FastCGI server
#
location ~ \.php$ {
include snippets/fastcgi-php.conf;
#fastcgi_split_path_info ^(.+\.php)(/.+)$;
# With php-fpm (or other unix sockets):
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
#fastcgi_index index.php;
# With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
但现在,当我尝试使用docker compose run webserver
启动它时,出现以下错误:
2019/07/20 08:55:09 [emerg] 1#1: open() "/etc/nginx/snippets/fastcgi-php.conf" failed (2: No such file or directory) in /etc/nginx/conf.d/default.conf:59
nginx: [emerg] open() "/etc/nginx/snippets/fastcgi-php.conf" failed (2: No such file or directory) in /etc/nginx/conf.d/default.conf:59
我知道它找不到文件fastcgi-php.conf。但这是为什么呢?该文件不应该包含在标准nginx安装中吗?
nginx full
包中,但您使用的图像nginx:latest
没有安装nginx full
包
要拥有它,您需要从nginx:latest
&在其中安装nginx full
,编写自己的dockerfile库:
Dockerfile:
FROM nginx:latest
RUN apt-get update && apt-get install -y nginx-full
version: '3'
services:
webserver:
build: .
image: mynginx:latest
docker compose.yaml:
FROM nginx:latest
RUN apt-get update && apt-get install -y nginx-full
version: '3'
services:
webserver:
build: .
image: mynginx:latest
将Dockerfile
和docker compose.yaml
放在同一文件夹中,然后将其向上移动
另外,如果您不介意使用其他人的回购协议(表示非官方),您可以从dockerhub中搜索一个,例如我从dockerhub中找到的一个(schleyk/nginx full
):
您正在尝试使用docker compose配置,该配置不考虑您尝试加载fastcgi/php特定选项的原因 您可以使用其他图像并将其链接到web服务器,如:
volumes:
- ./code:/code
- ./site.conf:/etc/nginx/conf.d/site.conf
links:
- php
php:
image: php:7-fpm
volumes:
- ./code:/code
Source,更详细的解释:是否可以在docker compose文件中安装附加软件包?不,这是docker文件的设计选择,docker compose不用于此目的,正如
build.
在compose文件中可以在docker compose up-d
或docker compose up-d--build
时为您进行构建,因此将其放入docker文件是最好的做法&我猜不会为您增加任何工作量。或者,您可以将软件包安装到docker文件中,标记它,将您自己的图像放入dockerhub,然后你的docker compose可以只使用你的图像,不需要定义构建:。
,这对所有成员都是透明的。嗯,好吧,这可能是一个好主意,它已经包括了nginx、php7.3和mysqlon。有很多,但我不得不说这与docker的最佳包装不一致。Docker的规则是一个服务一个容器,另请参见Separet db&webapp到不同容器的示例:但是,如果您坚持,Docker也可以为您执行此操作,请参阅