Last active
December 5, 2024 02:20
-
-
Save Nuxnuxx/f21b9c701ace378bad38d106c636877a to your computer and use it in GitHub Desktop.
Nixpacks for laravel with reverb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[phases.setup] | |
nixPkgs = ["...", "python311Packages.supervisor"] | |
[phases.build] | |
cmds = [ | |
"mkdir -p /etc/supervisor/conf.d/", | |
"cp /assets/laravel-worker.conf /etc/supervisor/conf.d/laravel-worker.conf", | |
"cp /assets/supervisord.conf /etc/supervisord.conf", | |
"chmod +x /assets/start.sh", | |
"npm run build", | |
"..." | |
] | |
[start] | |
cmd = '/assets/start.sh' | |
[staticAssets] | |
"start.sh" = ''' | |
#!/bin/bash | |
# Transform the nginx configuration | |
node /assets/scripts/prestart.mjs /assets/nginx.template.conf /etc/nginx.conf | |
# Start PHP-FPM | |
php-fpm -y /assets/php-fpm.conf | |
# Start Supervisor | |
supervisord -c /etc/supervisord.conf | |
# Start Nginx | |
nginx -c /etc/nginx.conf | |
''' | |
"supervisord.conf" = ''' | |
[unix_http_server] | |
file=/assets/supervisor.sock | |
[supervisord] | |
logfile=/var/log/supervisord.log | |
logfile_maxbytes=50MB | |
logfile_backups=10 | |
loglevel=info | |
pidfile=/assets/supervisord.pid | |
nodaemon=false | |
silent=false | |
minfds=1024 | |
minprocs=200 | |
[rpcinterface:supervisor] | |
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface | |
[supervisorctl] | |
serverurl=unix:///assets/supervisor.sock | |
[include] | |
files = /etc/supervisor/conf.d/*.conf | |
''' | |
"laravel-worker.conf" = ''' | |
[program:laravel-worker] | |
process_name=%(program_name)s_%(process_num)02d | |
command=php /app/artisan queue:work --queue=emails,process_files,reply --sleep=3 --tries=3 --max-time=3600 | |
autostart=true | |
autorestart=true | |
stopasgroup=true | |
killasgroup=true | |
numprocs=8 | |
startsecs=0 | |
stopwaitsecs=3600 | |
stdout_logfile=/var/log/laravel-worker.log | |
stderr_logfile=/var/log/laravel-worker.log | |
[program:reverb] | |
process_name=%(program_name)s_%(process_num)02d | |
command=php /app/artisan reverb:start | |
autostart=true | |
autorestart=true | |
stopasgroup=true | |
killasgroup=true | |
numprocs=1 | |
startsecs=0 | |
stopwaitsecs=3600 | |
stdout_logfile=/var/log/reverb.log | |
stderr_logfile=/var/log/reverb.log | |
''' | |
"php-fpm.conf" = ''' | |
[www] | |
listen = 127.0.0.1:9000 | |
user = www-data | |
group = www-data | |
listen.owner = www-data | |
listen.group = www-data | |
pm = dynamic | |
pm.max_children = 50 | |
pm.min_spare_servers = 4 | |
pm.max_spare_servers = 32 | |
pm.start_servers = 18 | |
clear_env = no | |
''' | |
"nginx.template.conf" = ''' | |
user www-data www-data; | |
worker_processes 5; | |
daemon off; | |
worker_rlimit_nofile 8192; | |
events { | |
worker_connections 4096; # Default: 1024 | |
} | |
http { | |
include $!{nginx}/conf/mime.types; index index.html index.htm index.php; | |
default_type application/octet-stream; | |
log_format main '$remote_addr - $remote_user [$time_local] $status ' | |
'"$request" $body_bytes_sent "$http_referer" ' | |
'"$http_user_agent" "$http_x_forwarded_for"'; | |
access_log /var/log/nginx-access.log; | |
error_log /var/log/nginx-error.log; | |
sendfile on; | |
tcp_nopush on; | |
server_names_hash_bucket_size 128; # this seems to be required for some vhosts | |
server { | |
listen 80; | |
listen [::]:80; | |
server_name localhost; | |
location / { | |
proxy_http_version 1.1; | |
proxy_set_header Host $http_host; | |
proxy_set_header Scheme $scheme; | |
proxy_set_header SERVER_PORT $server_port; | |
proxy_set_header REMOTE_ADDR $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header Upgrade $http_upgrade; | |
proxy_set_header Connection "Upgrade"; | |
proxy_pass http://0.0.0.0:8081; | |
} | |
$if(NIXPACKS_PHP_ROOT_DIR) ( | |
root ${NIXPACKS_PHP_ROOT_DIR}; | |
) else ( | |
root /app; | |
) | |
add_header X-Content-Type-Options "nosniff"; | |
client_max_body_size 50M; | |
index index.php; | |
charset utf-8; | |
$if(IS_LARAVEL) ( | |
location / { | |
try_files $uri $uri/ /index.php?$query_string; | |
} | |
) else () | |
$if(NIXPACKS_PHP_FALLBACK_PATH) ( | |
location / { | |
try_files $uri $uri/ ${NIXPACKS_PHP_FALLBACK_PATH}?$query_string; | |
} | |
) else () | |
location = /favicon.ico { access_log off; log_not_found off; } | |
location = /robots.txt { access_log off; log_not_found off; } | |
$if(IS_LARAVEL) ( | |
error_page 404 /index.php; | |
) else () | |
location ~ \.php$ { | |
fastcgi_pass 127.0.0.1:9000; | |
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; | |
include $!{nginx}/conf/fastcgi_params; | |
include $!{nginx}/conf/fastcgi.conf; | |
fastcgi_param PHP_VALUE "upload_max_filesize=500M \n post_max_size=50M"; | |
} | |
location ~ /\.(?!well-known).* { | |
deny all; | |
} | |
} | |
} | |
''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment