2016-08-24 16 views
2

私はDockerでSymfony3を設定しようとしています。 -DockerとnginxのSymfony 3

ドッキングウィンドウ・コンコード:

ファイル:: - - ドッキングウィンドウ-compose.yml site.conf

ディレクトリ

は、私は2つのファイルと私のプロジェクトフォルダ内の1つのディレクトリを持っています.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はhostsファイルで宣言されています。

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のインストールが含まれています。

私が最初にやることは、ドッカーの作成ではなく、次に私のためのすべてのイメージをインストールし、実行されるようです。

私はブラウザに、その後行くと、私のURLバーに次のように入力します。

http://test-api.local/ 

と、この: http://test-api.local/app.php と、この: http://test-api.local/app_dev.php

私はこのエラーを取得する:

502 Bad Gateway 

nginx/1.11.1 

私のコマンズラインには何も起こりません。誰も私のセットアップで何かが間違って見ることができます...?

答えて

0

Hmm。あなたのnginxがファイルを提供しようとしている/ PHPコンテナのソケットに接続しようとしているようです。しかし、コンテナはお互いを見ることができません。

phpコンテナ内にnginxを埋め込むか、ファイルとボリューム間でコンテナ間の/var/run/php5-fpm.sockソケットを共有する必要があります。

+0

docker-compose.ymlに2つのコンテナをリンクしていますが、リンクがあります.... – John

+0

はい - dns経由で!つまり、Webコンテナ内で 'ping php'を実行できますが、それだけです!ちなみに、docker-composeファイルのバージョン2では、ネットワークに有利なリンクが非推奨になっています。これにより、何が起こっているのかが少し分かります。作成ファイルをアップグレードしたい場合があります。 – Matthew

+0

hmmm大丈夫ですか? – John

3

SymfonyプロジェクトをDocker Composeと連携させるために必要な変更点は次のとおりです。 docker-compose.yml

site.conf
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 

、これらの行に変更:

fastcgi_pass php:9000; 
  • php

    fastcgi_pass unix:/var/run/php5-fpm.sock; 
    

    は、PHPのコンテナ(1の名前を指し君は docker-compose.ymlファイルで定義されています)。

  • 9000は、PHP-FPM用に公開されているPHPコンテナです。

私はそれをテストし、すべて正常に動作します。