Score:0

nginx and php-fpm waiting for server too long

ke flag

Hi I am using docker to mount nginx and a PHP-fpm using Falcon as a framework and react as the front end

`upstream fastcgi_backend {
server bfy-%APP_VERSION_UID%_buildify-php-fpm_1:90%FPM_PORT_PREFIX%;
}

server {
# Port 80 will require Nginx to be started with root permissions
# Depending on how you install Nginx to use port 80 you will need
# to start the server with `sudo` ports about 1000 do not require
# root privileges
# listen      80;

listen        80;
server_name $hostname;

##########################
# In production require SSL
# listen 443 ssl default_server;

# ssl on;
# ssl_session_timeout  5m;
# ssl_protocols  SSLv2 SSLv3 TLSv1;
# ssl_ciphers  ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
# ssl_prefer_server_ciphers   on;

# These locations depend on where you store your certs
# ssl_certificate        /var/nginx/certs/default.cert;
# ssl_certificate_key    /var/nginx/certs/default.key;
##########################

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

# This is the folder that index.php is in
root /var/www/html/public;
index index.php index.html index.htm;

charset utf-8;
client_max_body_size 100M;
fastcgi_read_timeout 1800;

open_file_cache max=100;
output_buffers 5 256k;

set_real_ip_from 172.18.0.9;
real_ip_header X-Real-IP;

# Represents the root of the domain
# http://localhost:8000/[index.php]
location / {
    # Matches URLS `$_GET['_url']`
    try_files $uri $uri/ /index.php?_url=$uri&$args;
}

# When the HTTP request does not match the above
# and the file ends in .php
location ~ [^/]\.php(/|$) {
    # try_files $uri =404;

    # Ubuntu and PHP7.0-fpm in socket mode
    # This path is dependent on the version of PHP install
    fastcgi_pass  fastcgi_backend;


    # Alternatively you use PHP-FPM in TCP mode (Required on Windows)
    # You will need to configure FPM to listen on a standard port
    # https://www.nginx.com/resources/wiki/start/topics/examples/phpfastcgionwindows/
    # fastcgi_pass  127.0.0.1:9000;

    fastcgi_index /index.php;

    include fastcgi_params;
    fastcgi_split_path_info ^(.+?\.php)(/.*)$;
    if (!-f $document_root$fastcgi_script_name) {
        return 404;
    }

    fastcgi_param PATH_INFO       $fastcgi_path_info;
    # fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
    # and set php.ini cgi.fix_pathinfo=0

    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_buffers 64 4k;
    fastcgi_busy_buffers_size 24k;
    fastcgi_buffer_size 16k;
    fastcgi_read_timeout 600s;
    fastcgi_connect_timeout 600s;
}

location ~ /\.ht {
    deny all;
}

location ~* /collections.json$ {
        try_files $uri $uri/ /index.php?_url=$uri&$args;
}

location /products/ {
    location ~* .js$ {
        try_files $uri $uri/ /index.php?_url=$uri&$args;
    }
}

location /collections/ {
    location ~* /products.json$ {
        try_files $uri $uri/ /index.php?_url=$uri&$args;
    }
}

location ~* \.(js|json|css|png|jpg|jpeg|gif|ico)$ {
    expires       max;
    log_not_found off;
    access_log    off;
}

gzip on;
gzip_disable "msie6";

gzip_comp_level 6;
gzip_min_length 1100;
gzip_buffers 16 8k;
gzip_proxied any;
gzip_types
    text/plain
    text/css
    text/js
    text/xml
    text/javascript
    application/javascript
    application/x-javascript
    application/json
    application/xml
    application/xml+rss
    image/svg+xml;
gzip_vary on;
}

and this is the php-fpm config file

[global]
; Pid file
; Note: the default prefix is /var
; Default Value: none
pid = /run/php-fpm.pid

; Error log file
; If it's set to "syslog", log is sent to syslogd instead of being written into a 
local file.
; Note: the default prefix is /var
error_log = /proc/self/fd/2


; syslog_ident is prepended to every message. If you have multiple FPM
; instances running on the same server, you can change the default value
; which must suit common needs.
; Default Value: php-fpm
;syslog.ident = php-fpm

; Log level
; Possible Values: alert, error, warning, notice, debug
; Default Value: notice
log_level = notice

; If this number of child processes exit with SIGSEGV or SIGBUS within the time
; interval set by emergency_restart_interval then FPM will restart. A value
; of '0' means 'Off'.
; Default Value: 0
;emergency_restart_threshold = 0

process_control_timeout = 0

daemonize = no

; Set open file descriptor rlimit for the master process.
; Default Value: system defined value
rlimit_files = 1024

; Set max core size rlimit for the master process.
; Possible Values: 'unlimited' or an integer greater or equal to 0
; Default Value: system defined value
rlimit_core = 0

; Specify the event mechanism FPM will use. The following is available:
; - select     (any POSIX os)
; - poll       (any POSIX os)
; - epoll      (linux >= 2.5.44)
; - kqueue     (FreeBSD >= 4.1, OpenBSD >= 2.9, NetBSD >= 2.0)
; - /dev/poll  (Solaris >= 7)
; - port       (Solaris >= 10)
; Default Value: not set (auto detection)
events.mechanism = epoll


[www]
; if we send this to /proc/self/fd/1, it never appears
access.log = /proc/self/fd/1

user = %FPM_USER%
group = %FPM_GROUP%

;listen.owner = root
;listen.group = root
;listen.mode = 0660
;listen.allowed_clients = 127.0.0.1
listen = 0.0.0.0:%FPM_PORT%

pm = dynamic
pm.max_children = 200
pm.start_servers = 15
pm.min_spare_servers = 15
pm.max_spare_servers = 25
pm.max_requests = 500
pm.process_idle_timeout = 10s

clear_env = no

; Ensure worker stdout and stderr are sent to the main error log.
catch_workers_output = yes

; for debugging 1h
request_terminate_timeout = 3600

Now I am using it as headless e-commerce using Shopify APIs. The Response from the api is fast but the page takes about 12 seconds to load when I check the requests I see almost all the times is spent waiting for the server Please see screenshot even if I remove the api calls the page takes the same time to load

I want to improve the server response time so that the page does not take 10-12 seconds to load I tried reducing and increasing the pm.max_childern and other pm properties but it did not made a difference. I am using FROM php:7.2-fpm AS phalcon_build.

Is there something wrong with the configuration that is causing the page to load slow?

ws flag
While there's quite a few issues with your config, you haven't asked a question nor provided any information to support a diagnosis of why your site is slow.
djdomi avatar
za flag
Questions seeking installation, configuration or diagnostic help must include the desired end state, the specific problem or error, sufficient information about the configuration and environment to reproduce it, and attempted solutions. Questions without a clear problem statement are not useful to other readers and are unlikely to get good answers. See [ask]
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.