gpt4 book ai didi

php - 带有Docker和Nginx的Symfony 3

转载 作者:行者123 更新时间:2023-12-02 18:12:07 42 4
gpt4 key购买 nike

我正在尝试使用Docker配置Symfony3。

我的项目文件夹中有两个文件和一个目录:

文件:
-docker-compose.yml
-site.conf

目录:
-代码

docker-compose.yml:

web:
image: nginx:latest
ports:
- "80:80"
volumes:
- ./site.conf:/etc/nginx/conf.d/site.conf
links:
- php
php:
image: php:7-fpm
volumes:
- ./test_api:/test_api/web

site.conf:

我是从Nginx官方网站 here获得此文件的
我的server_name在主机文件中声明。
server {
server_name test-api.local;
root /var/www/project/web;

location / {
# try to serve file directly, fallback to app.php
try_files $uri /app.php$is_args$args;
}
# DEV
# This rule should only be placed on your development environment
# In production, don't include this and don't deploy app_dev.php or config.php
location ~ ^/(app_dev|config)\.php(/|$) {
fastcgi_pass unix:/var/run/php5-fpm.sock;
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;
}
# PROD
location ~ ^/app\.php(/|$) {
fastcgi_pass unix:/var/run/php5-fpm.sock;
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/project_error.log;
access_log /var/log/nginx/project_access.log;
}

代码目录:

它包含全新的Symfony 3.1安装。

不,我首先要做的是docker-compose up,然后为我安装所有镜像并似乎可以运行。

然后,我进入浏览器,并在网址栏中输入以下内容:
http://test-api.local/

还有这个:
http://test-api.local/app.php
还有这个:
http://test-api.local/app_dev.php

我收到此错误:
502 Bad Gateway

nginx/1.11.1

我的命令线没有错误,什么也没发生。有人能看到我的设置有问题吗?

最佳答案

这是您需要应用的更改,以使Symfony项目与Docker Compose一起使用。

docker-compose.yml中:

web:
image: nginx:latest
ports:
- "80:80"
volumes:
- ./site.conf:/etc/nginx/conf.d/site.conf
# Add the volumes from the PHP container, as Nginx needs access to your project files
volumes_from:
- php
links:
- php

php:
image: php:7-fpm
volumes:
# I changed to the path that is specified in your site.conf file
- ./test_api:/var/www/project

site.conf中,更改以下行:
fastcgi_pass unix:/var/run/php5-fpm.sock;


fastcgi_pass php:9000;
  • php引用您的PHP容器的名称(您在docker-compose.yml文件中定义的名称)。
  • 9000是PHP容器为PHP-FPM公开的端口。

  • 我对其进行了测试,一切正常。

    关于php - 带有Docker和Nginx的Symfony 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39126359/

    42 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com