Docker를 사용하여 PHP 웹 응용 프로그램을 구성하려고합니다. 아이디어는 php-fpm독립형 컨테이너에서 앱을 실행하고 nginx를 실행할 다른 컨테이너를 갖는 것입니다. 이 설정의 아이디어는 동일한 nginx 컨테이너를 사용하여 동일한 컴퓨터에서 이미 작동하는 다른 웹 응용 프로그램에 요청을 프록시하는 것입니다. 문제는 nginx요청에 대한 요청이 계속 진행되면서 정적 파일 (js, css 등)을 올바르게 처리 할 수 없다는 것 fpm입니다.
파일 시스템은 다음과 같습니다.
/
├── Makefile
├── config
│ └── webapp.config
└── webapp
└── web
├── index.php
└── static.js
나는 Makefile다음과 같은 것을 사용하여 모든 것을 실행하고 있습니다 (이것에 관심이 없습니다 docker-compose) :
PWD:=$(shell pwd)
CONFIG:='/config'
WEBAPP:='/webapp'
run: | run-network run-webapp run-nginx
run-network:
docker network create internal-net
run-webapp:
docker run --rm \
--name=webapp \
--net=internal-net \
--volume=$(PWD)$(WEBAPP):/var/www/webapp:ro \
-p 9000:9000 \
php:5.6.22-fpm-alpine
run-nginx:
docker run --rm \
--name=nginx \
--net=internal-net \
--volume=$(PWD)$(CONFIG)/webapp.conf:/etc/nginx/conf.d/webapp.domain.com.conf:ro \
-p 80:80 \
nginx:1.11.0-alpine
이것이 내 config/webapp.conf모습입니다.
server {
listen 80;
server_name webapp.domain.com;
# This is where the index.php file is located in the webapp container
# This folder will contain an index.php file and some static files that should be accessed directly
root /var/www/webapp/web;
location / {
try_files $uri $uri/ @webapp;
}
location @webapp {
rewrite ^(.*)$ /index.php$1 last;
}
location ~ ^/index\.php(/|$) {
include fastcgi_params;
fastcgi_pass webapp:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
}
}
해당 index.php파일을 사용하여 처리해야하는 모든 작업 이 작동합니다. 그러나 정적 파일은 제공되지 않으므로 404오류가 발생합니다 (php webapp에는 실제로 경로가 구성되어 있지 않기 때문에). 나는 그들이 실제로 때의 nginx 시도는 자체 컨테이너 파일 시스템에서 해당로드 믿고 webapp용기에 다시 실패 @webapp.
nginx다른 컨테이너에있는 파일을 제공 하도록 구성 할 수있는 방법이 있습니까?
nginxPHP 응용 프로그램 내에서 요청 파일을 만들지 않고 프록시를 사용하기 fpm위해 nginx정적 비 PHP 파일에 액세스 해야 합니다.
webapp컨테이너가 아닌 컨테이너에 볼륨으로 마운트됩니다 nginx.