From d21edfec4a58594bb3984f2a8e16cdf098f5649a Mon Sep 17 00:00:00 2001 From: Frank Kloeker Date: Mon, 5 May 2025 15:47:35 +0200 Subject: [PATCH 1/3] introduce FASTCGI_READ_TIMEOUT make `fastcgi_read_timeout` in nginx configurable to increase stream connection while import POST requests Signed-off-by: Frank Kloeker --- README.md | 1 + root/entrypoint.sh | 1 + root/etc/wallabag/nginx.template.conf | 73 +++++++++++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 root/etc/wallabag/nginx.template.conf diff --git a/README.md b/README.md index af05b00..5543f4d 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ Default login is `wallabag:wallabag`. - `-e POPULATE_DATABASE=...`(defaults to "True". Does the DB has to be populated or is it an existing one) - `-e SYMFONY__ENV__SERVER_NAME=...` (defaults to "Your wallabag instance". Specifies a user-friendly name for the 2FA issuer) - `-e PHP_MEMORY_LIMIT=...` (allows you to change the PHP `memory_limit` value. defaults to 128M, and should be a number and unit, eg. 512K, 128M, 2G, or a number of bytes) +- `-e FASTCGI_READ_TIMEOUT=...` (allows you to change the timeout how nginx handle cgi backend connection to PHP. default is 300s for 5 minutes) ## SQLite diff --git a/root/entrypoint.sh b/root/entrypoint.sh index 0d3932f..3221c64 100755 --- a/root/entrypoint.sh +++ b/root/entrypoint.sh @@ -29,6 +29,7 @@ provisioner() { # Replace environment variables envsubst < /etc/wallabag/parameters.template.yml > app/config/parameters.yml envsubst < /etc/wallabag/php-wallabag.template.ini > /etc/php81/conf.d/50_wallabag.ini + envsubst < /etc/wallabag/nginx.template.conf > /etc/nginx/nginx.conf # Wait for external database if [ "$SYMFONY__ENV__DATABASE_DRIVER" = "pdo_mysql" ] || [ "$SYMFONY__ENV__DATABASE_DRIVER" = "pdo_pgsql" ] ; then diff --git a/root/etc/wallabag/nginx.template.conf b/root/etc/wallabag/nginx.template.conf new file mode 100644 index 0000000..ffb0f7e --- /dev/null +++ b/root/etc/wallabag/nginx.template.conf @@ -0,0 +1,73 @@ +user nginx; +worker_processes 1; +pid /var/run/nginx.pid; + +events { + worker_connections 2048; + multi_accept on; + use epoll; +} + +http { + + server_tokens off; + sendfile on; + tcp_nopush on; + tcp_nodelay on; + keepalive_timeout 15; + types_hash_max_size 2048; + include /etc/nginx/mime.types; + default_type application/octet-stream; + access_log off; + error_log off; + gzip on; + gzip_disable "msie6"; + open_file_cache max=100; + client_max_body_size 100M; + + map $http_x_forwarded_proto $fe_https { + default $https; + https on; + } + + upstream php-upstream { + server 127.0.0.1:9000; + } + + server { + listen [::]:80 ipv6only=off; + server_name _; + root /var/www/wallabag/web; + + location / { + # try to serve file directly, fallback to app.php + try_files $uri /app.php$is_args$args; + } + + location ~ ^/app\.php(/|$) { + fastcgi_pass php-upstream; + fastcgi_split_path_info ^(.+\.php)(/.*)$; + include fastcgi_params; + # When you are using symlinks to link the document root to the + # current version of your application, you should pass the real + # application path instead of the path to the symlink to PHP + # FPM. + # Otherwise, PHP's OPcache may not properly detect changes to + # your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126 + # for more information). + fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; + fastcgi_param DOCUMENT_ROOT $realpath_root; + fastcgi_read_timeout ${FASTCGI_READ_TIMEOUT:-300s}; + # Prevents URIs that include the front controller. This will 404: + # http://domain.tld/app.php/some-path + # Remove the internal directive to allow URIs like this + internal; + } + + access_log /var/log/nginx/access.log; + error_log /var/log/nginx/error.log; + } + +} + +daemon off; From eb038898eaeefde7120beac2c3a7bddb61844bb3 Mon Sep 17 00:00:00 2001 From: Frank Kloeker Date: Mon, 5 May 2025 16:34:36 +0200 Subject: [PATCH 2/3] replace only FASTCGI_READ_TIMEOUT Signed-off-by: Frank Kloeker --- root/entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/root/entrypoint.sh b/root/entrypoint.sh index 3221c64..8d95a8a 100755 --- a/root/entrypoint.sh +++ b/root/entrypoint.sh @@ -29,7 +29,7 @@ provisioner() { # Replace environment variables envsubst < /etc/wallabag/parameters.template.yml > app/config/parameters.yml envsubst < /etc/wallabag/php-wallabag.template.ini > /etc/php81/conf.d/50_wallabag.ini - envsubst < /etc/wallabag/nginx.template.conf > /etc/nginx/nginx.conf + envsubst '${FASTCGI_READ_TIMEOUT}' < /etc/wallabag/nginx.template.conf > /etc/nginx/nginx.conf # Wait for external database if [ "$SYMFONY__ENV__DATABASE_DRIVER" = "pdo_mysql" ] || [ "$SYMFONY__ENV__DATABASE_DRIVER" = "pdo_pgsql" ] ; then From b55f138b84991260b11ba7f40c46744d1414dc10 Mon Sep 17 00:00:00 2001 From: Frank Kloeker Date: Mon, 5 May 2025 16:58:51 +0200 Subject: [PATCH 3/3] prevent replace of existing vars Signed-off-by: Frank Kloeker --- root/entrypoint.sh | 2 +- root/etc/wallabag/nginx.template.conf | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/root/entrypoint.sh b/root/entrypoint.sh index 8d95a8a..b5a777c 100755 --- a/root/entrypoint.sh +++ b/root/entrypoint.sh @@ -29,7 +29,7 @@ provisioner() { # Replace environment variables envsubst < /etc/wallabag/parameters.template.yml > app/config/parameters.yml envsubst < /etc/wallabag/php-wallabag.template.ini > /etc/php81/conf.d/50_wallabag.ini - envsubst '${FASTCGI_READ_TIMEOUT}' < /etc/wallabag/nginx.template.conf > /etc/nginx/nginx.conf + envsubst '${FASTCGI_READ_TIMEOUT}' < /etc/wallabag/nginx.template.conf | sed 's/\$\${/\${/g' > /etc/nginx/nginx.conf # Wait for external database if [ "$SYMFONY__ENV__DATABASE_DRIVER" = "pdo_mysql" ] || [ "$SYMFONY__ENV__DATABASE_DRIVER" = "pdo_pgsql" ] ; then diff --git a/root/etc/wallabag/nginx.template.conf b/root/etc/wallabag/nginx.template.conf index ffb0f7e..f12dae9 100644 --- a/root/etc/wallabag/nginx.template.conf +++ b/root/etc/wallabag/nginx.template.conf @@ -25,8 +25,8 @@ http { open_file_cache max=100; client_max_body_size 100M; - map $http_x_forwarded_proto $fe_https { - default $https; + map $$http_x_forwarded_proto $$fe_https { + default $$https; https on; } @@ -41,12 +41,12 @@ http { location / { # try to serve file directly, fallback to app.php - try_files $uri /app.php$is_args$args; + try_files $$uri /app.php$$is_args$$args; } - location ~ ^/app\.php(/|$) { + location ~ ^/app\.php(/|$$) { fastcgi_pass php-upstream; - fastcgi_split_path_info ^(.+\.php)(/.*)$; + fastcgi_split_path_info ^(.+\.php)(/.*)$$; include fastcgi_params; # When you are using symlinks to link the document root to the # current version of your application, you should pass the real @@ -55,8 +55,8 @@ http { # Otherwise, PHP's OPcache may not properly detect changes to # your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126 # for more information). - fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; - fastcgi_param DOCUMENT_ROOT $realpath_root; + fastcgi_param SCRIPT_FILENAME $$realpath_root$$fastcgi_script_name; + fastcgi_param DOCUMENT_ROOT $$realpath_root; fastcgi_read_timeout ${FASTCGI_READ_TIMEOUT:-300s}; # Prevents URIs that include the front controller. This will 404: # http://domain.tld/app.php/some-path