我正在尝试建立一个新的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/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安装中吗?
答案 0 :(得分:2)
/etc/nginx/snippets/fastcgi-php.conf
在nginx-full
软件包中,但是您使用的映像nginx:latest
未安装nginx-full
软件包。
要拥有它,您需要从nginx:latest
编写自己的dockerfile库并在其中安装nginx-full
:
Dockerfile:
FROM nginx:latest
RUN apt-get update && apt-get install -y nginx-full
docker-compose.yaml:
version: '3'
services:
webserver:
build: .
image: mynginx:latest
将Dockerfile
和docker-compose.yaml
放在同一文件夹中,然后将其向上。
此外,如果您不介意使用其他人的存储库(意味着不是官方的),则可以从dockerhub中搜索一个,例如我从dockerhub(schleyk/nginx-full
)中找到了一个:
docker run -it --rm schleyk/nginx-full ls -alh /etc/nginx/snippets/fastcgi-php.conf
-rw-r--r-- 1 root root 422 Apr 6 2018 /etc/nginx/snippets/fastcgi-php.conf
答案 1 :(得分:1)
您正在尝试使用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
来源,其中有更详尽的说明:http://geekyplatypus.com/dockerise-your-php-application-with-nginx-and-php7-fpm/