首頁  >  文章  >  後端開發  >  ngnix 加 php-fpm配置

ngnix 加 php-fpm配置

不言
不言原創
2018-04-09 16:48:061590瀏覽

本篇文章给大家分享的内容是关于ngnix 加 php-fpm配置 ,有需要的朋友可以参考一下

文章参考: https://www.cnblogs.com/f-ck-need-u/p/7627035.html

nginx 502 参考 : https://blog.csdn.net/wzqzhq/article/details/53320533

cygwin启动脚本

#!/bin/bash
for i in `ps x | grep php-fpm | awk '{print $1 }'`;do kill -9 $i;done
/usr/sbin/php-fpm.exe
#/usr/sbin/php-fpm restart

#/usr/sbin/nginx.exe -s reload
#netstat -anpo | grep "php-cgi" | wc -l
#awk -F: '{print NR,NF,$NF,"\t",$0}' /etc/passwd   //依次打印行号,字段数,最后字段值,制表符,每行内容


#/usr/sbin/nginx -s reload
for i in `ps x | grep nginx | awk '{print $1}'`;do kill -9 $i;done
/usr/sbin/nginx >> /var/log/nginx.log.new 2>&1 && echo $?

nginx 配置

user www;
worker_processes  4;
worker_rlimit_nofile 30000;

error_log  /usr/local/nginx/logs/error.log;
pid        /usr/local/nginx/logs/nginx.pid;

events {
    use epoll;
    worker_connections  10240;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    #access_log /usr/local/nginx/logs/access.log;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  75;
    tcp_nodelay        on;

    gzip  on;
    gzip_min_length  512;
    gzip_disable "MSIE [1-6]\.(?!.*SV1)";
    gzip_buffers     4 8k;
    gzip_types       text/html text/xml text/plain application/x-javascript text/css application/xml;

    server_names_hash_bucket_size 128;
    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
    fastcgi_buffer_size 64k;
    fastcgi_buffers 4 64k;
    fastcgi_busy_buffers_size 128k;
    fastcgi_temp_file_write_size 128k;

    include /usr/local/nginx/conf/sites-enabled/*;
}

sites-enabled/test.com 配置

server {
        listen   80;
        #listen   443 ssl;

        #ssl_certificate      /etc/cert/test.com.chained.crt;
        #ssl_certificate_key  /etc/cert/test.com.key;

        server_name      test.com;
        access_log       /usr/local/nginx/logs/$host.log;

        set $server_root /home/test/root;

        root  $server_root;

        location / {
                index  index.php index.htm index.html;
                if (!-f $request_filename) {
                        rewrite  ^/(.*)_v=* /$1  last;
                }
        }

        location ~ \.php$ {
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  $server_root$fastcgi_script_name;
                include /usr/local/nginx/conf/fastcgi_params;
        }

        location ~ \.(htm|html|gif|jpg|jpeg|png|bmp|ico|rar|css|js|zip|java|jar|txt|flv|swf|mid|doc|ppt|xls|pdf|txt|mp3|wma|json|xml)$ {
                expires 7d;
        }
}

2. php-fpm 配置

pid = run/php-fpm.pid
error_log = log/php-fpm.log
log_level = notice
; pool name ('www' here)
[www]
listen = 127.0.0.1:9000
listen.owner = www
listen.group = www
listen.mode = 0666
user = www
group = www
; Choose how the process manager will control the number of child processes.
; Possible Values:
;   static  - a fixed number (pm.max_children) of child processes;
;   dynamic - the number of child processes are set dynamically based on the
;             following directives:
;             pm.max_children      - the maximum number of children that can
;                                    be alive at the same time.
;             pm.start_servers     - the number of children created on startup.
;             pm.min_spare_servers - the minimum number of children in 'idle'
;                                    state (waiting to process). If the number
;                                    of 'idle' processes is less than this
;                                    number then some children will be created.
;             pm.max_spare_servers - the maximum number of children in 'idle'
;                                    state (waiting to process). If the number
;                                    of 'idle' processes is greater than this
;                                    number then some children will be killed.
; Note: This value is mandatory.
pm = dynamic

; The number of child processes to be created when pm is set to 'static' and the
; maximum number of child processes to be created when pm is set to 'dynamic'.
; This value sets the limit on the number of simultaneous requests that will be
; served. Equivalent to the ApacheMaxClients directive with mpm_prefork.
; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP
; CGI.
; Note: Used when pm is set to either 'static' or 'dynamic'
; Note: This value is mandatory.
pm.max_children = 50

; The number of child processes created on startup.
; Note: Used only when pm is set to 'dynamic'
; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2
pm.start_servers = 20
; The desired minimum number of idle server processes.
; Note: Used only when pm is set to 'dynamic'
; Note: Mandatory when pm is set to 'dynamic'
pm.min_spare_servers = 5

; The desired maximum number of idle server processes.
; Note: Used only when pm is set to 'dynamic'
; Note: Mandatory when pm is set to 'dynamic'
pm.max_spare_servers = 35

; The number of requests each child process should execute before respawning.
; This can be useful to work around memory leaks in 3rd party libraries. For
; endless request processing specify '0'. Equivalent to PHP_FCGI_MAX_REQUESTS.
; Default Value: 0
pm.max_requests = 500
; Pass environment variables like LD_LIBRARY_PATH. All $VARIABLEs are taken from
; the current environment.
; Default Value: clean env
env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp

; Additional php.ini defines, specific to this pool of workers. These settings
; overwrite the values previously defined in the php.ini. The directives are the
; same as the PHP SAPI:
;   php_value/php_flag             - you can set classic ini defines which can
;                                    be overwritten from PHP call 'ini_set'.
;   php_admin_value/php_admin_flag - these directives won't be overwritten by
;                                     PHP call 'ini_set'
; For php_*flag, valid values are on, off, 1, 0, true, false, yes or no.

; Defining 'extension' will load the corresponding shared extension from
; extension_dir. Defining 'disable_functions' or 'disable_classes' will not
; overwrite previously defined php.ini values, but will append the new value
; instead.

; Note: path INI options can be relative and will be expanded with the prefix
; (pool, global or /usr/local/php5)

; Default Value: nothing is defined by default except the values in php.ini and
;                specified at startup with the -d argument
;php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f www@my.domain.com
;php_flag[display_errors] = off
;php_admin_value[error_log] = /var/log/fpm-php.www.log
;php_admin_flag[log_errors] = on
;php_admin_value[memory_limit] = 32M
request_terminate_timeout = 300

相关推荐:

php配置php-fpm启动参数及配置详

php版本切换的详细过程和线上Linux环境下常见php-fpm常见问题

PHP-FPM中两种进程管理模式

以上是ngnix 加 php-fpm配置的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn