2017-10-09 51 views
1

我有兩個碼頭容器:nginx和php-fpm。如何使自包含的nginx和php-fpm容器正確

我想讓它們自成一體(容器將從git構建時克隆回購)用於生產。但在克隆回購後,我需要在項目文件夾中創建一些初始內容,如composer install。我可以在php-fpm容器內做到這一點,因爲我在那裏有PHP。但是如何在nginx容器中準備代碼?我沒有用於作曲家的PHP。

一切都很好,當我將相同的初始化文件夾掛載到兩個容器。

也許我做錯了什麼,爲nginx + php-fpm做自包含容器的最佳方法是什麼?

現在我有這個nginx的-配置:

server { 
    listen  80; 
    server_name localhost; 

    index index.php index.html; 

    # I need only /api/ path 
    location /api/ { 
     try_files $uri $uri/ /index.php?$query_string; 
    } 

    location ~ \.php$ {  
     root /var/www/public; 
     try_files $uri =404; 
     fastcgi_split_path_info ^(.+\.php)(/.+)$; 
     fastcgi_pass api:9000; 
     fastcgi_index index.php; 
     include fastcgi_params; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
     fastcgi_param PATH_INFO $fastcgi_path_info; 
    } 
} 

回答

1

您應該只有在FPM服務器上的PHP文件。正如你之前所說的,你應該用php cli在該服務器上運行作曲家。你不應該在nginx服務器上需要任何PHP文件。 SCRIPT_FILENAME將由CGI服務器解析,因此Web代理上不需要存在位置。如果您需要對nginx服務器進行配置更改,則可能需要使用像Salt,Chef或Puppet等更多系統導向的配置。

location ~ \.php$ { 
    # This is the webserver root for static junk 
    root /var/www/public; 
    ... 
    # Point this somewhere else if the docroot is in a different location on the FPM server. 
    fastcgi_param SCRIPT_FILENAME /home/php-fpm/wwwroot/$fastcgi_script_name; 
} 
+1

謝謝,你的回答幫了我。我從頭開始,然後我能夠正確設置nginx和fpm,它可以工作。 –

相關問題