我有一个 Coolify 环境,其中包含一个由 PHP Web 服务器和 nginx 代理组成的 docker compose。nginx 代理提供静态文件并充当 PHP 服务器的代理。
我在 Coolify 中设置了两个域,如下所示
https://app.example.org:80
,https://static.example.org:80
这是我的 Docker 撰写文件:
version: '3.8'
services:
app:
image: php:8.3-fpm-alpine
container_name: php-app
working_dir: /var/www/html
volumes:
# - ./:/var/www/html
- ./config:/var/www/html/config
- ./backup:/var/www/html/backup
- ./userdata:/var/www/html/userdata
- ./.logs:/var/www/html/.logs
ports:
- "9000:9000"
environment:
PHP_OPCACHE_ENABLE: "1"
PHP_OPCACHE_MEMORY_CONSUMPTION: "128"
build:
context: .
dockerfile: Dockerfile
networks:
- app-network
webserver:
image: nginx:alpine
container_name: nginx-web
volumes:
- ./nginx/sites:/etc/nginx/sites
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
- ./shared_assets:/var/www/html/shared_assets
- ./instances:/var/www/html/instances
environment:
- ENVIRONMENT=production
ports:
- "89:80"
depends_on:
- app
networks:
- app-network
networks:
app-network:
对于 Nginx,我配置了两个站点
server {
listen 80;
server_name static.example.org;
root /var/www/html/shared_assets;
index index.html index.htm;
# Serve static files from the shared_assets folder
location /assets/ {
alias /var/www/html/shared_assets/assets/; # Fix the alias path to match the actual filesystem location
try_files $uri $uri/ =404;
}
}
server {
listen 80;
server_name app.example.org;
root /var/www/html/instances/app/public;
index index.php;
add_header Access-Control-Allow-Origin "*";
location / {
try_files $uri /index.php$is_args$args;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass app:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~ /\.ht {
deny all;
}
}
静态文件服务正常,但应用程序提示网关超时。此设置在我本地机器上运行良好。
知道可能是什么问题吗?
问题是 fpm 只监听 127.0.0.1 上的请求。添加
RUN sed -i 's/^listen = .*/listen = 0.0.0.0:9000/' /usr/local/etc/php-fpm.d/www.conf
到 Dockerfile 后解决了该问题。