ฉันพยายามกำหนดค่า php webapp โดยใช้ docker แนวคิดคือการเรียกใช้แอปที่ใช้php-fpmในคอนเทนเนอร์แบบสแตนด์อโลนและมีคอนเทนเนอร์อื่นที่จะเรียกใช้ nginx แนวคิดสำหรับการตั้งค่านี้คือการใช้คอนเทนเนอร์ nginx เดียวกันกับคำขอพร็อกซีไปยัง webapps อื่น ๆ ที่ทำงานบนเครื่องเดียวกันอยู่แล้ว ปัญหาคือฉันไม่สามารถ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ให้บริการไฟล์เหล่านั้นที่อยู่ในภาชนะอื่นหรือไม่?
nginxร้องขอไฟล์ภายในแอปพลิเคชัน php ฉันกำลังfpmจะทำเช่นนั้นและฉันจำเป็นต้องnginxเข้าถึงไฟล์ที่ไม่ใช่ php คงที่
                webappคอนเทนเนอร์เท่านั้นไม่ใช่ในตัวnginxเดียว