Skip to content

Commit

Permalink
Merge pull request #15 from mintopia/develop
Browse files Browse the repository at this point in the history
Update to allow nginx and FPM status paths to be specified
  • Loading branch information
mintopia authored Nov 22, 2023
2 parents bb6419f + 7c5dd8f commit fc88a94
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 34 deletions.
27 changes: 21 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ services:
user: "1000"
env_file: .env
restart: unless-stopped
scale: 2
deploy:
replicas: 2
depends_on:
- db
- redis
Expand Down Expand Up @@ -166,18 +167,32 @@ Run the stack with `docker-compose up -d` and the DB migrations using `docker-co

By default the production containers run using nginx and php-fpm with a very conservative number of workers. You can control the number with the following environment variables in `.env` or directly on the `php-fpm` container:

```
FPM_PM_MAX_CHILDREN=50
```dotenv
FPM_PM_MAX_CHILDREN=40
FPM_PM_START_SERVERS=10
FPM_PM_MIN_SPARE_SERVERS=5
FPM_PM_MAX_SPARE_SERVERS=10
FPM_PM_MIN_SPARE_SERVERS=10
FPM_PM_MAX_SPARE_SERVERS=30
```

These are used in the FPM configuration file, you can find more on configuring it in the php-fpm documentation.

### Performance Monitoring

You can monitor the nginx and php-fpm status using `/nginx-status` and `/fpm-status` HTTP endpoints. By default these are only allowed to be used by localhost and they shouldn't be exposed to the internet. You can control the IP range allowed to access them using the `STATUS_ALLOW` environment variable on the nginx container. It supports anything available for an `allow` command in nginx config.
You can monitor the nginx and php-fpm status using `/nginx-status` and `/fpm-status` HTTP endpoints. There is also an FPM ping endpoint at `/fpm-ping`.

By default these are only allowed to be used by localhost and they shouldn't be exposed to the internet. You can control the IP range allowed to access them using the `STATUS_ALLOW` environment variable on the nginx container. It supports anything available for an `allow` command in nginx config.

If you want to change these paths, set the environment variables `NGINX_STATUS_PATH`, `FPM_STATUS_PATH` and `FPM_PING_PATH` on both nginx and php-fpm.

For example, if you wanted to use an unpredicatable string in the URL and allow access to all IPs:

```dotenv
STATUS_ALLOW=0.0.0.0/0
FPM_STATUS_PATH=/410a821c-ac93-4b07-8652-7924937ce920/fpm-status
FPM_PING_PATH=/410a821c-ac93-4b07-8652-7924937ce920/fpm-ping
NGINX_STATUS_PATH=/410a821c-ac93-4b07-8652-7924937ce920/nginx-status
```

## Usage

Expand Down
48 changes: 24 additions & 24 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ services:
command: "artisan queue:work"
user: "1000"
env_file: .env
scale: 2
deploy:
replicas: 2
volumes:
- ./:/app
depends_on:
Expand Down
14 changes: 11 additions & 3 deletions docker/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ map $http_upgrade $type {
server {
listen 80;
index index.php index.html;
access_log /dev/stdout;
access_log /dev/stdout main;
error_log /dev/stderr;
root /var/www/public;
client_max_body_size 8M;
Expand All @@ -15,15 +15,23 @@ server {
try_files /nonexistent @$type;
}

location ~ ^/(fpm-status|fpm-ping)$ {
location ${FPM_STATUS_PATH} {
access_log off;
allow ${STATUS_ALLOW};
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass php-fpm:9000;
}

location /nginx-status {
location ${FPM_PING_PATH} {
access_log off;
allow ${STATUS_ALLOW};
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass php-fpm:9000;
}

location ${NGINX_STATUS_PATH} {
stub_status on;
access_log off;
allow ${STATUS_ALLOW};
Expand Down

0 comments on commit fc88a94

Please sign in to comment.