使用PHP和NGINX不起作用的Docker-Compose
我在Docker-Compose中具有非常简单的配置,其中 php:7-fpm
和 nginx
我想用来托管简单的PHP网站。但是我遇到的问题在生产中可用。
有人可以告诉我我做错了什么吗?
这是docker-compose.prod.yml:
version: '3.8'
services:
web:
image: nginx:latest
ports:
- "8080:80"
volumes:
- ../company/site:/code
- ./site.prod.conf:/etc/nginx/conf.d/default.conf
php:
image: php:7-fpm
volumes:
- ../company/site:/code
这是site.prod.conf文件:
server {
listen 80;
index index.php index.html;
server_name example.com;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /code;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
我可以编写,日志似乎很好,当我运行Docker PS:
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c268a9cf4716 php:7-fpm "docker-php-entrypoi…" 27 minutes ago Up 16 seconds 9000/tcp example_code-php-1
beaaec39209b nginx:latest "/docker-entrypoint.…" 27 minutes ago Up 16 seconds 0.0.0.0:8080->80/tcp, :::8080->80/tcp example_code-web-1
然后检查端口时,我认为这看起来很好:
netstat -tulpn | grep :80
tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 204195/docker-proxy
tcp6 0 0 :::8080 :::* LISTEN 204207/docker-proxy
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
“ 8080:80”更改为
“ 80:80”
。"8080:80"
to"80:80"
.您必须检查日志以找出错误。 https://docs.docker.com/engine/engine/eengine/reference/commandline/logs/logs/logs/ < / a>
这些问题可能发生:
是Docker Docker最佳实践: https:// docs。 docker.com/develop/dev-best-practices/
https://docks.docker.com/devevelovely.com/devevelovelvelvement-develop-images-images-images-images/dockerfile_best-practerices /
这里,我建议此docker-compose.prod.yml
在 与此Docker-compose.prod.yml文件相同的目录,创建一个php-fpm目录:
mkdir php-fpm
(或Docker-Compose中build> build> build> build> buold>的目录架构。 prod.yml文件。)
在php-fpm目录中,请添加此dockerfile,称为
dockerfile
当然,添加php扩展名您需要您的项目。在这里,您有一个示例如何安装GD,PDO_MYSQL,BCMatch,MySQLI,INTL。但是还有其他扩展名称为curl,xml,xdebug,mcrypt,memcache等...
in您的nginx配置,应使用端口443定义https的配置。还请更新此行
fastcgi_pass php:9000;
。用容器名称替换php
。当然,容器名称必须是唯一的。然后,建立您的设置
You must check the logs to find out the error. https://docs.docker.com/engine/reference/commandline/logs/
These issues can happen :
Here is Docker Docker best practices : https://docs.docker.com/develop/dev-best-practices/
https://docs.docker.com/develop/develop-images/dockerfile_best-practices/
Here, I suggest this docker-compose.prod.yml
In the same directory as this docker-compose.prod.yml file, create a php-fpm directory:
mkdir php-fpm
(or directory architecture written underbuild
in docker-compose.prod.yml file.)In php-fpm directory, please add this Dockerfile called
Dockerfile
Of course, add the PHP extensions that you need for your project. Here you have an example how to install gd, pdo_mysql, bcmatch, mysqli, intl. But there are others extension as curl, xml, xdebug, mcrypt, memcache, etc... https://github.com/mlocati/docker-php-extension-installer
In your nginx configuration, you should define config for HTTPS with port 443. Please also update this line
fastcgi_pass php:9000;
. Replacephp
by the container name. Of course, container name must be unique.Then, build your set-up