Join the community today
Register Now

Nginx How to Connection = keep-alive?

Discussion in 'Centmin Mod Insights' started by RoldanLT, Jul 10, 2014.

Tags:
  1. RoldanLT

    RoldanLT Well-Known Member

    3,787
    928
    113
    May 25, 2014
    Phillipines
    Ratings:
    +1,252
    Local Time:
    4:53 AM
    1.11
    10.2
  2. eva2000

    eva2000 Administrator Staff Member

    27,771
    6,336
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,339
    Local Time:
    6:53 AM
    Nginx 1.13.x
    MariaDB 5.5
    did you enable php.conf include file /usr/local/nginx/conf/php.conf settings to disable php keep alives ?

    Code:
    # might shave 200+ ms off PHP requests
    # which don't pass on a content length header
    # slightly faster page response time at the
    # expense of throughput / scalability
    #sendfile on;
    #tcp_nopush off;
    #keepalive_requests 0;
    i have keep alives enabled as I am using multiple php-fpm pools with upstream keepalive set
     
  3. RoldanLT

    RoldanLT Well-Known Member

    3,787
    928
    113
    May 25, 2014
    Phillipines
    Ratings:
    +1,252
    Local Time:
    4:53 AM
    1.11
    10.2
    Here's what I have:
    Code:
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass   127.0.0.1:9000;
        #fastcgi_pass   unix:/tmp/php5-fpm.sock;
        fastcgi_index  index.php;
        #fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_param  SCRIPT_FILENAME    $request_filename;
    
    # might shave 200+ ms off PHP requests
    # which don't pass on a content length header
    # slightly faster page response time at the
    # expense of throughput / scalability
    sendfile on;
    tcp_nopush off;
    keepalive_requests 0;
    
    fastcgi_connect_timeout 60;
    fastcgi_send_timeout 180;
    fastcgi_read_timeout 180;
    fastcgi_buffer_size 512k;
    fastcgi_buffers 512 16k;
    fastcgi_busy_buffers_size 512k;
    fastcgi_temp_file_write_size 512k;
    fastcgi_intercept_errors on;
    
    # old pre .03 method
    #fastcgi_param HTTPS on;
    
    #new .04+ map method
    fastcgi_param HTTPS $server_https;
    
    # comment out PATH_TRANSLATED line if /usr/local/lib/php.ini sets following:
    # cgi.fix_pathinfo=0
    # as of centminmod v1.2.3-eva2000.01 default is set to cgi.fix_pathinfo=1
    
    fastcgi_param  PATH_INFO          $fastcgi_path_info;
    fastcgi_param  PATH_TRANSLATED    $document_root$fastcgi_path_info;
    
    fastcgi_param  QUERY_STRING       $query_string;
    fastcgi_param  REQUEST_METHOD     $request_method;
    fastcgi_param  CONTENT_TYPE       $content_type;
    fastcgi_param  CONTENT_LENGTH     $content_length;
    
    fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
    fastcgi_param  REQUEST_URI        $request_uri;
    fastcgi_param  DOCUMENT_URI       $document_uri;
    fastcgi_param  DOCUMENT_ROOT      $document_root;
    fastcgi_param  SERVER_PROTOCOL    $server_protocol;
    
    fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
    fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;
    
    fastcgi_param  REMOTE_ADDR        $remote_addr;
    fastcgi_param  REMOTE_PORT        $remote_port;
    fastcgi_param  SERVER_ADDR        $server_addr;
    fastcgi_param  SERVER_PORT        $server_port;
    fastcgi_param  SERVER_NAME        $server_name;
    
    # PHP only, required if PHP was built with --enable-force-cgi-redirect
    fastcgi_param  REDIRECT_STATUS    200;
    
                       }location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass   127.0.0.1:9000;
        #fastcgi_pass   unix:/tmp/php5-fpm.sock;
        fastcgi_index  index.php;
        #fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_param  SCRIPT_FILENAME    $request_filename;
    
    # might shave 200+ ms off PHP requests
    # which don't pass on a content length header
    # slightly faster page response time at the
    # expense of throughput / scalability
    sendfile on;
    tcp_nopush off;
    keepalive_requests 0;
    
    fastcgi_connect_timeout 60;
    fastcgi_send_timeout 180;
    fastcgi_read_timeout 180;
    fastcgi_buffer_size 512k;
    fastcgi_buffers 512 16k;
    fastcgi_busy_buffers_size 512k;
    fastcgi_temp_file_write_size 512k;
    fastcgi_intercept_errors on;
    
    # old pre .03 method
    #fastcgi_param HTTPS on;
    
    #new .04+ map method
    fastcgi_param HTTPS $server_https;
    
    # comment out PATH_TRANSLATED line if /usr/local/lib/php.ini sets following:
    # cgi.fix_pathinfo=0
    # as of centminmod v1.2.3-eva2000.01 default is set to cgi.fix_pathinfo=1
    
    fastcgi_param  PATH_INFO          $fastcgi_path_info;
    fastcgi_param  PATH_TRANSLATED    $document_root$fastcgi_path_info;
    
    fastcgi_param  QUERY_STRING       $query_string;
    fastcgi_param  REQUEST_METHOD     $request_method;
    fastcgi_param  CONTENT_TYPE       $content_type;
    fastcgi_param  CONTENT_LENGTH     $content_length;
    
    fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
    fastcgi_param  REQUEST_URI        $request_uri;
    fastcgi_param  DOCUMENT_URI       $document_uri;
    fastcgi_param  DOCUMENT_ROOT      $document_root;
    fastcgi_param  SERVER_PROTOCOL    $server_protocol;
    
    fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
    fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;
    
    fastcgi_param  REMOTE_ADDR        $remote_addr;
    fastcgi_param  REMOTE_PORT        $remote_port;
    fastcgi_param  SERVER_ADDR        $server_addr;
    fastcgi_param  SERVER_PORT        $server_port;
    fastcgi_param  SERVER_NAME        $server_name;
    
    # PHP only, required if PHP was built with --enable-force-cgi-redirect
    fastcgi_param  REDIRECT_STATUS    200;
    
                       }
     
  4. eva2000

    eva2000 Administrator Staff Member

    27,771
    6,336
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,339
    Local Time:
    6:53 AM
    Nginx 1.13.x
    MariaDB 5.5
    yeah you turned off keepalives to get potentially faster PHP request response times

    Code:
    keepalive_requests 0;
    I kept keepalives as I am using multiple php-fpm pools in upstream keep alive state
     
  5. RoldanLT

    RoldanLT Well-Known Member

    3,787
    928
    113
    May 25, 2014
    Phillipines
    Ratings:
    +1,252
    Local Time:
    4:53 AM
    1.11
    10.2
    Can you please create a tutorial on how to implement this?
    Thanks You very much!
     
  6. RoldanLT

    RoldanLT Well-Known Member

    3,787
    928
    113
    May 25, 2014
    Phillipines
    Ratings:
    +1,252
    Local Time:
    4:53 AM
    1.11
    10.2
    Which is better and optimal? Just comment it out?
    Please advice.
     
  7. eva2000

    eva2000 Administrator Staff Member

    27,771
    6,336
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,339
    Local Time:
    6:53 AM
    Nginx 1.13.x
    MariaDB 5.5
    Already answered back on G+ Community at https://plus.google.com/118067102985043487274/posts/jm8rYbs8WuC

    Already mentioned it at https://community.centminmod.com/threads/switch-from-tcp-to-unix-domain-sockets.307/#post-1442 but you're on your own regarding implementing that as Centmin Mod is probably best left using the single PHP-FPM pool for future Centmin Mod upgrade compatibility unless you want to break upgrades and future features that assume a single PHP-FPM pool is in use.
     
  8. RoldanLT

    RoldanLT Well-Known Member

    3,787
    928
    113
    May 25, 2014
    Phillipines
    Ratings:
    +1,252
    Local Time:
    4:53 AM
    1.11
    10.2
    With this settings:
    sendfile on;
    tcp_nopush off;
    keepalive_requests 0;
    Equals =

    And with this settings commented out:
    #sendfile on;
    #tcp_nopush off;
    #keepalive_requests 0;
    Equals =
    Am I right ?
     
  9. eva2000

    eva2000 Administrator Staff Member

    27,771
    6,336
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,339
    Local Time:
    6:53 AM
    Nginx 1.13.x
    MariaDB 5.5
    reverse them ;)
     
    • Like Like x 1
  10. RoldanLT

    RoldanLT Well-Known Member

    3,787
    928
    113
    May 25, 2014
    Phillipines
    Ratings:
    +1,252
    Local Time:
    4:53 AM
    1.11
    10.2
    hahah my bad OK :D
    Thanks!
     
  11. RoldanLT

    RoldanLT Well-Known Member

    3,787
    928
    113
    May 25, 2014
    Phillipines
    Ratings:
    +1,252
    Local Time:
    4:53 AM
    1.11
    10.2
  12. eva2000

    eva2000 Administrator Staff Member

    27,771
    6,336
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,339
    Local Time:
    6:53 AM
    Nginx 1.13.x
    MariaDB 5.5