This repository was archived by the owner on Oct 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 41
This repository was archived by the owner on Oct 17, 2024. It is now read-only.
docker fpm fallback 502 bad gateway #32
Copy link
Copy link
Open
Description
My docker-compose
#Docker Networks
networks:
app-network:
driver: bridge
services:
app:
build: php-fpm
container_name: app
restart: always
ports:
- "9501:9501"
# - "9000:9000"
# - "81:81"
expose:
- 80
- 9501
- 9000
# entrypoint: "php vendor/scil/laravel-fly/bin/fly start"
entrypoint: "php-fpm"
environment:
SERVICE_NAME: app
SERVICE_TAGS: dev
volumes:
- ${APP_PATH_HOST}:${APP_PATH_CONTAINER}
- ./php-fpm/config:/usr/local/etc/php
working_dir: ${APP_PATH_CONTAINER}
networks:
- app-network
#Nginx Service
nginx:
build: nginx
restart: always
ports:
- "80:80"
- "443:443"
networks:
- app-network
working_dir: /app
volumes:
- ${APP_PATH_HOST}/public:/usr/share/nginx/html
- ./nginx/conf.d/app.conf:/etc/nginx/nginx.conf
command: [nginx-debug, '-g', 'daemon off;']
db:
image: mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: 123456
volumes:
- ${DB_PATH_HOST}:/var/lib/mysql
command: --default-authentication-plugin=mysql_native_password
ports:
- "3306:3306"
networks:
- app-network
adminer:
image: adminer
restart: always
ports:
- "6080:8080"
networks:
- app-network
My nginx app.conf
user www-data www-data;
worker_processes 5;
pid /var/run/nginx.pid;
worker_rlimit_nofile 1024;
# include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 512;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
sendfile off;
tcp_nopush on;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log warn;
upstream default {
server app:9501 weight=1 max_fails=1 fail_timeout=10 ;
server app:81 backup;
# The connections parameter sets the maximum number of idle keepalive connections to upstream servers that are preserved in the cache of each worker process. When this number is exceeded, the least recently used connections are closed.
# It does not limit the total number of connections to upstream servers that an nginx worker process can open. The connections parameter should be set to a number small enough to let upstream servers process new incoming connections as well.
# https://gist.github.com/magnetikonline/4a2e68b2ce94bd0c945e
# https://ma.ttias.be/enable-keepalive-connections-in-nginx-upstream-proxy-configurations/
keepalive 8;
}
upstream swoole {
server app:9501;
}
upstream fpm {
server app:81;
}
# map to different upstream backends based on query parameter 'useserver'
# visit http://fly.test/?useserver=swoole to use server swoole
# visit http://fly.test to use upstream default
map $arg_useserver $pool {
default "default";
swoole "swoole";
fpm "fpm";
}
log_format my_upstream '$remote_addr|$time_local|$request_time|$upstream_response_time|$status '
'$upstream_addr|$request';
server {
server_name fly.test;
listen 80;
root /usr/share/nginx/html;
index index.html;
charset utf-8;
location = / {
# if you have a static home page , try this one:
# try_files index.html @other;
try_files '' @php;
}
location / {
try_files $uri $uri/ @php;
}
location @php {
proxy_pass http://$pool;
# Default is HTTP/1, keepalive is only enabled in HTTP/1.1
proxy_http_version 1.1;
# Remove the Connection header if the client sends it,
# it could be "close" to close a keepalive connection
proxy_set_header Connection "";
# proxy_connect_timeout 60s;
# proxy_send_timeout 60s;
# proxy_read_timeout 120s;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
# proxy_set_header X-Real-PORT $remote_port;
# proxy_set_header Scheme $scheme;
# proxy_set_header Server-Protocol $server_protocol;
# proxy_set_header Server-Name $server_name;
# proxy_set_header Server-Addr $server_addr;
# proxy_set_header Server-Port $server_port;
# just a mark for different upstream server, you can disable it
add_header X-Upstream $upstream_addr;
# log
access_log /var/log/nginx/upstream.log my_upstream;
}
# # only for Let's Encrypt
# location ~ /.well-known {
# allow all;
# # set root is necessage, otherwise "Invalid response from domain..."
# # https://www.digitalocean.com/community/questions/letsencrypt-problem-renewing-certs-invalid-response-from-domain
# root {{ doc_root }};
# }
}
server {
server_name fly.test;
listen 81;
root /usr/share/nginx/html;
index index.html index.php;
charset utf-8;
location / {
try_files '' /index.php?$query_string;
}
location /index.php {
fastcgi_pass app:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
}
}
Swoole works well, but php-fpm always get 502 bad gateway
Metadata
Metadata
Assignees
Labels
No labels