1+ [phases .setup ]
2+ nixPkgs = [" ..." , " python311Packages.supervisor" , " nano" , " less" ]
3+
4+ [phases .build ]
5+ cmds = [
6+ " mkdir -p /etc/supervisor/conf.d/" ,
7+ " cp /assets/worker-*.conf /etc/supervisor/conf.d/" ,
8+ " cp /assets/supervisord.conf /etc/supervisord.conf" ,
9+ " chmod +x /assets/start.sh" ,
10+ " ..." ,
11+ # Change folder permissions for Laravel
12+ " chmod -R 775 /app/storage /app/bootstrap/cache" ,
13+ " chown -R www-data:www-data /app" ,
14+ " chown -R www-data:www-data /app/storage" ,
15+ " chown -R www-data:www-data /app/bootstrap/cache" ,
16+ ]
17+
18+ [start ]
19+ cmd = ' /assets/start.sh'
20+
21+ [staticAssets ]
22+ "start.sh" = '''
23+ #!/bin/bash
24+
25+ # Transform the nginx configuration
26+ node /assets/scripts/prestart.mjs /assets/nginx.template.conf /etc/nginx.conf
27+
28+ # Start supervisor
29+ supervisord -c /etc/supervisord.conf -n
30+ '''
31+
32+ "supervisord.conf" = '''
33+ [unix_http_server]
34+ file=/assets/supervisor.sock
35+
36+ [supervisord]
37+ logfile=/var/log/supervisord.log
38+ logfile_maxbytes=50MB
39+ logfile_backups=10
40+ loglevel=info
41+ pidfile=/assets/supervisord.pid
42+ nodaemon=false
43+ silent=false
44+ minfds=1024
45+ minprocs=200
46+
47+ [rpcinterface:supervisor]
48+ supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
49+
50+ [supervisorctl]
51+ serverurl=unix:///assets/supervisor.sock
52+
53+ [include]
54+ files = /etc/supervisor/conf.d/*.conf
55+ '''
56+
57+ "worker-nginx.conf" = '''
58+ [program:worker-nginx]
59+ process_name=%(program_name)s_%(process_num)02d
60+ command=nginx -c /etc/nginx.conf
61+ autostart=true
62+ autorestart=true
63+ stdout_logfile=/var/log/worker-nginx.log
64+ stderr_logfile=/var/log/worker-nginx.log
65+ '''
66+
67+ "worker-phpfpm.conf" = '''
68+ [program:worker-phpfpm]
69+ process_name=%(program_name)s_%(process_num)02d
70+ command=php-fpm -y /assets/php-fpm.conf -F
71+ autostart=true
72+ autorestart=true
73+ stdout_logfile=/var/log/worker-phpfpm.log
74+ stderr_logfile=/var/log/worker-phpfpm.log
75+ '''
76+
77+ "worker-laravel.conf" = '''
78+ [program:worker-laravel]
79+ process_name=%(program_name)s_%(process_num)02d
80+ command=bash -c 'sleep 60; exec php /app/artisan queue:work --sleep=3 --tries=3 --max-time=3600'
81+ autostart=true
82+ autorestart=true
83+ stopasgroup=true
84+ killasgroup=true
85+ numprocs=8
86+ startsecs=0
87+ stopwaitsecs=3600
88+ stdout_logfile=/var/log/worker-laravel.log
89+ stderr_logfile=/var/log/worker-laravel.log
90+ '''
91+
92+ "php-fpm.conf" = '''
93+ [www]
94+ listen = 127.0.0.1:9000
95+ user = www-data
96+ group = www-data
97+ listen.owner = www-data
98+ listen.group = www-data
99+ pm = dynamic
100+ pm.max_children = 50
101+ pm.min_spare_servers = 4
102+ pm.max_spare_servers = 32
103+ pm.start_servers = 18
104+ clear_env = no
105+ '''
106+
107+ "nginx.template.conf" = '''
108+ user www-data www-data;
109+ worker_processes 5;
110+ daemon off;
111+
112+ worker_rlimit_nofile 8192;
113+
114+ events {
115+ worker_connections 4096; # Default: 1024
116+ }
117+
118+ http {
119+ include $!{nginx}/conf/mime.types;
120+ index index.html index.htm index.php;
121+
122+ default_type application/octet-stream;
123+ log_format main '$remote_addr - $remote_user [$time_local] $status '
124+ '"$request" $body_bytes_sent "$http_referer" '
125+ '"$http_user_agent" "$http_x_forwarded_for"';
126+ access_log /var/log/nginx-access.log;
127+ error_log /var/log/nginx-error.log;
128+ sendfile on;
129+ tcp_nopush on;
130+ server_names_hash_bucket_size 128; # this seems to be required for some vhosts
131+
132+ server {
133+ listen ${PORT};
134+ listen [::]:${PORT};
135+ server_name localhost;
136+
137+ $if(NIXPACKS_PHP_ROOT_DIR) (
138+ root ${NIXPACKS_PHP_ROOT_DIR};
139+ ) else (
140+ root /app;
141+ )
142+
143+ add_header X-Content-Type-Options "nosniff";
144+
145+ client_max_body_size 35M;
146+
147+ index index.php;
148+
149+ charset utf-8;
150+
151+ $if(IS_LARAVEL) (
152+ location / {
153+ try_files $uri $uri/ /index.php?$query_string;
154+ }
155+ ) else ()
156+
157+ $if(NIXPACKS_PHP_FALLBACK_PATH) (
158+ location / {
159+ try_files $uri $uri/ ${NIXPACKS_PHP_FALLBACK_PATH}?$query_string;
160+ }
161+ ) else ()
162+
163+ location = /favicon.ico { access_log off; log_not_found off; }
164+ location = /robots.txt { access_log off; log_not_found off; }
165+
166+ $if(IS_LARAVEL) (
167+ error_page 404 /index.php;
168+ ) else ()
169+
170+ location ~ \.php$ {
171+ fastcgi_pass 127.0.0.1:9000;
172+ fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
173+ include $!{nginx}/conf/fastcgi_params;
174+ include $!{nginx}/conf/fastcgi.conf;
175+
176+ fastcgi_param PHP_VALUE "upload_max_filesize=30M \n post_max_size=35M";
177+ }
178+
179+ location ~ /\.(?!well-known).* {
180+ deny all;
181+ }
182+ }
183+ }
184+ '''
0 commit comments