我正在尝试在Windows机器上用NGINX和PHP-FPM在Docker中设置Symfony 3。目前,我得到一个502坏网关错误。我将FPM端口从9000更改为8000,因为在我的主机上,端口9000已被hyper-v服务vmms使用。exe。我不知道这是否有关系。
docker-compose.yml
version: "3"
services:
nginx:
build: ./nginx
volumes:
- ./symfony:/usr/shared/nginx/html
ports:
- "80:80"
- "443:443"
environment:
- NGINX_HOST=free-energy.org
depends_on:
- fpm
fpm:
image: php:fpm
ports:
- "8000:8000"
# It seems like FPM receives the full path from NGINX
# and tries to find the files in this dock, so it must
# be the same as nginx.root
volumes:
- ./symfony:/usr/shared/nginx/html
Dockerfile NGINX:
FROM nginx:1.13.7-alpine
# Change Nginx config here...
RUN rm /etc/nginx/conf.d/default.conf
ADD ./default.conf /etc/nginx/conf.d/
EXPOSE 80
EXPOSE 443
违约conf override NGINX:
server {
listen 80;
server_name free-energy.org;
# this path MUST be exactly as docker-compose.fpm.volumes,
# even if it doesn't exist in this dock.
root /usr/share/nginx/html;
location / {
try_files $uri /index.php$is_args$args;
}
location ~ ^/.+\.php(/|$) {
fastcgi_pass fpm:8000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
我们将这样猜测一周,尝试使用这个:/docker-compose.yml
version: "2"
services:
nginx:
build: "./docker/nginx/"
container_name: "nginx-free-energy"
volumes_from:
- php-fpm
restart: always
ports:
- "80:80"
php-fpm:
image: php:7.1-fpm
container_name: "php-fpm-free-energy"
volumes:
- ./src/free-energy.org:/var/www/free-energy.org
restart: always
expose:
- "9000"
/docker/nginx/Dockerfile
FROM nginx
COPY config/free-energy.conf /etc/nginx/conf.d/free-energy.conf
RUN rm /etc/nginx/conf.d/default.conf
RUN usermod -u 1000 www-data
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
/docker/nginx/config/free energy。配置(用于symfony3应用程序)
server {
listen 80;
server_name www.free-energy.org free-energy.org;
root /var/www/free-energy.org/web;
location / {
# try to serve file directly, fallback to app.php
try_files $uri /app.php$is_args$args;
}
# PROD
location ~ ^/app\.php(/|$) {
fastcgi_pass php-fpm-free-energy:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
# When you are using symlinks to link the document root to the
# current version of your application, you should pass the real
# application path instead of the path to the symlink to PHP
# FPM.
# Otherwise, PHP's OPcache may not properly detect changes to
# your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
# for more information).
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
# Prevents URIs that include the front controller. This will 404:
# http://domain.tld/app.php/some-path
# Remove the internal directive to allow URIs like this
internal;
}
# return 404 for all other php files not matching the front controller
# this prevents access to other php files you don't want to be accessible.
location ~ \.php$ {
return 404;
}
error_log /var/log/nginx/free-energy.org_error.log;
access_log /var/log/nginx/free-energy.org_access.log;
}
启动后,需要添加127.0。0.1自由能。org
到您的/etc/hosts文件中,用于解析主机,您的应用程序将在/src/free energy上运行。org(入口点是-/src/free energy.org/web/app.php)
随着0TshEL_n1ck的回答,解决了502错误。我仍然得到'文件未找到'在浏览器和相关的错误日志在NGINX'FastCGI发送在stderr:"主脚本未知"而读取响应头从上游'.
这是原来工作的配置。需要改变的关键:
这些要点是在使用位于https://symfony.com/doc/current/setup/web_server_configuration.html的Symfony文档的NGINX配置后发现的
这是有效的代码。
docker撰写。yml:
version: "3"
services:
nginx:
build: ./nginx
volumes:
- ./symfony:/var/www/symfony
ports:
- "80:80"
- "443:443"
depends_on:
- fpm
fpm:
image: php:fpm
ports:
- "9000"
volumes:
- ./symfony:/var/www/symfony
NGINX配置默认值。形态:
server {
listen 80;
server_name free-energy.org, www.free-energy.org;
root /var/www/symfony/public;
location / {
# try to serve file directly, fallback to index.php
try_files $uri /index.php$is_args$args;
}
location ~ ^/index\.php(/|$) {
fastcgi_pass fpm:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
# When you are using symlinks to link the document root to the
# current version of your application, you should pass the real
# application path instead of the path to the symlink to PHP
# FPM.
# Otherwise, PHP's OPcache may not properly detect changes to
# your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
# for more information).
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
# Prevents URIs that include the front controller. This will 404:
# http://domain.tld/index.php/some-path
# Remove the internal directive to allow URIs like this
internal;
}
# return 404 for all other php files not matching the front controller
# this prevents access to other php files you don't want to be accessible.
location ~ \.php$ {
return 404;
}
error_log /var/log/nginx/project_error.log;
access_log /var/log/nginx/project_access.log;
}
您能检查一下php fpm容器吗?我记得,php fpm默认端口是9000,而不是8000。将容器内部的端口映射从8000更改为9000
ports:
- "8000:9000"
或者如果它已经在您的主机上使用,您可以只在容器之间公开端口。
expose:
- "9000"
问题内容: 我在阅读有关docker的一个不错的问题-回答了有关docker实现细节的概述。我想知道在Windows平台上是否可以做这样的事情。 是否存在Windows替代Docker? 从理论上讲,可以使用其他(基于Windows的)组件来构建它吗? 更新1 : 稍微相关的问题(沙盒处理):是否存在用于Windows平台的轻型,可编程的Sandbox API? Update2 :: 有关如何在W
问题内容: 我在JAI和ImageIO库中搜索了64位窗口,但没有找到这些窗口的任何版本。6-7年前在Java Bug跟踪系统上的最后64位胜诉请求。 我认为,jai的开发人员不会为Win64发布任何版本。:( 我的问题是,我们可以为64位Windows从它们的源构建jai和imageio吗?怎么样? 非常感谢… 问题答案: 从源语言的角度来看,JAI和JAI Image I / O由两部分组成:
我正在尝试获取节点。js和npm在windows计算机上工作(它在MacOx和ubuntu上工作得非常好)。安装已完成,没有任何错误,但当我尝试使用npm安装任何东西时,我收到以下错误: 示例: 有人能帮我解决这个问题吗?
默认情况下 docker swarm 服务中暴露的端口在有外部请求时会通过 router mesh 进行负载均衡。查看文档时提到了两个绕过默认负载均衡的方式,。一种是在暴露端口时设置 --publish 参数的 mode 为 host,一种是设置 --endpoint-mode 为 dnsrr。这两种方式具体有什么区别?
问题内容: 请帮助我在此docker django配置中提供静态文件。 我正在进行的项目在交付时遇到了一些问题。 管理员视图的 所有静态文件都可以正常加载,但是客户端Web视图的静态文件则抛出404 Not found错误。 这是我的 配置详细信息: 更新 这是管理员静态文件url的样子: http //developer.com : 8000/ static/admin/css/ base.cs
所以我使用这种方法写入文件,它在windows上运行完全正常,但在mac上运行时,它会创建文件,但它们是空的。 我知道数据是正确的,因为它打印正确。感谢您的任何帮助,这真的让我绊倒了。