nginx和php整合安装过程记录1.nginx的配置;必须是指定 www⽤户和www⽤户组访问
groupadd www
useradd -g www www
daokr@DK:~$ cat /etc/f
user www www;
worker_processes auto;
pid /run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/pes;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
gzip_disable "msie6";
server
{
listen 1180;
server_name localhost;
charset    utf-8;
##ssl configure
#ssl                  on;
#ssl_certificate      cert/;
#ssl_certificate_key  cert/lianyinggufen_com.key;
#ssl_session_timeout  5m;
#ssl_protocols        SSLv3 TLSv1;
#ssl_ciphers          HIGH:!ADH:!EXPORT56:RC4+RSA:+MEDIUM;
#ssl_prefer_server_ciphers  on;
## phalcon-config
set $root_path "/home/daokr/web";
root $root_path;
index index.php index.html index.htm;
try_files $uri $uri/ @rewrite;
#for document_root - ajax request
location /
{
rewrite ^(.*)$ /index.php?_url=$1;
}
#for all others
location @rewrite
{
#rewrite ^/(.*)$ /index.php?_url=$1;
}
location ~ \.php
{
# try_files $uri=404;
#fastcgi_index index.php;
#fiastcgi_pass 127.0.0.1:9000;
include f;
#fpm的运⾏路径
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
#include fastcgi_params;
#fastcgi_split_path_info ^(.+\.php)(/.+)$;
#fastcgi_param PATH_INFO $fastcgi_path_info;
#fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
#fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
# cache folder
# location ~* ^/(js|css|img|images|flv|swf|fonts|download)/(.+)$
# cache file type
location ~* .(js|css|jpg|jpeg|gif|png|flv|swf|ttf|svg|eot|woff|apk|ipa|plist)$
{
root $root_path;
access_log  off;
expires    30d;
}
location ~ \.ico
{
root $root_path;
access_log  off;
expires    30d;
}
location ~ /\.ht
{
deny all;
}
}
}
#mail {
#    # See sample authentication script at:
#    # /ImapAuthenticateWithApachePhpScript
#
#    # auth_http localhost/auth.php;
#    # pop3_capabilities "TOP""USER";
#    # imap_capabilities "IMAP4rev1""UIDPLUS";
#
#    server {
#        listen    localhost:110;
#        protocol  pop3;
#        proxy      on;
#    }
#
#    server {
#        listen    localhost:143;
#        protocol  imap;
#        proxy      on;
#    }
#}
2.配置php7.0-fpm的配置⽂件
daokr@DK:~$ ps -aux |grep php-fpm
root    230580.00.81195208648 ?        Ss  17:520:00 php-fpm: master process (/etc/php/7.0/f) www      230590.00.91197049792 ?        S    17:520:00 php-fpm: pool www
www      230600.00.91197049564 ?        S    17:520:00 php-fpm: pool www
daokr    231010.00.06864808 pts/12  S+  18:010:00 grep --color=auto php-fpm
编辑 vim /etc/php/7.0/f 配置⽂件
根据该⽂件查看f ⽂件
重点修改第23⾏,24⾏  47⾏ 48⾏
报错提醒:php-fpm.sock failed (13: Permission denied)
49 listen.owner = daokr
up = daokr
daokr@DK:~$ cat /etc/php/7.0/fpm/pool.f
1 ; Start a new pool named 'www'.
2 ; the variable $pool can be used in any directive and will be replaced by the
3 ; pool name ('www' here)
4 [www]
5
6 ; Per pool prefix
7 ; It only applies on the following directives:
8 ; - 'access.log'
9 ; - 'slowlog'
10 ; - 'listen' (unixsocket)
11 ; - 'chroot'
12 ; - 'chdir'
13 ; - 'php_values'
14 ; - 'php_admin_values'
15 ; When not set, the global prefix (or /usr) applies instead.
16 ; Note: This directive can also be relative to the global prefix.
17 ; Default Value: none
18 ;prefix = /path/to/pools/$pool
19
20 ; Unix user/group of processes
21 ; Note: The user is mandatory. If the group is not set, the default user's group
22 ;      will be used.
23 user = www
24 group = www
25
26 ; The address on which to accept FastCGI requests.
27 ; Valid syntaxes are:
28 ;  'ss:port'    - to listen on a TCP socket to a specific IPv4 address on
29 ;                            a specific port;
30 ;  '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on
31 ;                            a specific port;
32 ;  'port'                - to listen on a TCP socket to all addresses
33 ;                            (IPv6 and IPv4-mapped) on a specific port;
34 ;  '/path/to/unix/socket' - to listen on a unix socket.
35 ; Note: This value is mandatory.
36 listen = /run/php/php7.0-fpm.sock
37
38 ; Set listen(2) backlog.
39 ; Default Value: 511 (-1 on FreeBSD and OpenBSD)
40 ;listen.backlog = 511
41
42 ; Set permissions for unix socket, if one is used. In Linux, read/write
43 ; permissions must be set in order to allow connections from a web server. Many
44 ; BSD-derived systems allow connections regardless of permissions.
45 ; Default Values: user and group are set as the running user
46 ;                mode is set to 0660
47 listen.owner = www
up = www
49 ;de = 0660
50 ; When POSIX Access Control Lists are supported you can set them using
51 ; these options, value is a comma separated list of user/group names.
52 ; When set, listen.owner up are ignored
53 ;listen.acl_users =
54 ;listen.acl_groups =
55
56 ; List of addresses (IPv4/IPv6) of FastCGI clients which are allowed to connect.
57 ; Equivalent to the FCGI_WEB_SERVER_ADDRS environment variable in the original
58 ; PHP FCGI (5.2.2+). Makes sense only with a tcp listening socket. Each address
59 ; must be separated by a comma. If this value is left blank, connections will be
60 ; accepted from any ip address.
61 ; Default Value: any
62 ;listen.allowed_clients = 127.0.0.1
63
64 ; Specify the nice(2) priority to apply to the pool processes (only if set)
65 ; The value can vary from -19 (highest priority) to 20 (lower priority)
66 ; Note: - It will only work if the FPM master process is launched as root
67 ;      - The pool processes will inherit the master process priority
68 ;        unless it specified otherwise
69 ; Default Value: no set
70 ; process.priority = -19
71
72 ; Choose how the process manager will control the number of child processes.
73 ; Possible Values:
74 ;  static  - a fixed number (pm.max_children) of child processes;
75 ;  dynamic - the number of child processes are set dynamically based on the
76 ;            following directives. With this process management, there will be
77 ;            always at least 1 children.
78 ;            pm.max_children      - the maximum number of children that can
79 ;                                    be alive at the same time.
80 ;            pm.start_servers    - the number of children created on startup.
81 ;            pm.min_spare_servers - the minimum number of children in'idle'
82 ;                                    state (waiting to process). If the number
83 ;                                    of 'idle' processes is less than this
84 ;                                    number then some children will be created.
85 ;            pm.max_spare_servers - the maximum number of children in'idle'
86 ;                                    state (waiting to process). If the number
87 ;                                    of 'idle' processes is greater than this
88 ;                                    number then some children will be killed.
89 ;  ondemand - no children are created at startup. Children will be forked when
90 ;            new requests will connect. The following parameter are used:
91 ;            pm.max_children          - the maximum number of children that
92 ;                                        can be alive at the same time.
93 ;            pm.process_idle_timeout  - The number of seconds after which
94 ;                                        an idle process will be killed.
95 ; Note: This value is mandatory.
96 pm = dynamic
97
98 ; The number of child processes to be created when pm is set to 'static' and the
99 ; maximum number of child processes when pm is set to 'dynamic' or 'ondemand'. 100 ; This value sets the limit on the number of simultaneous requests that will be
101 ; served. Equivalent to the ApacheMaxClients directive with mpm_prefork.
nginx和apache区别102 ; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP 103 ; CGI. The below defaults are based on a server without much resources. Don't
104 ; forget to tweak pm.* to fit your needs.
105 ; Note: Used when pm is set to 'static', 'dynamic' or 'ondemand'
106 ; Note: This value is mandatory.
107 pm.max_children = 5
108
109 ; The number of child processes created on startup.
110 ; Note: Used only when pm is set to 'dynamic'
111 ; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2 112 pm.start_servers = 2
113
114 ; The desired minimum number of idle server processes.
115 ; Note: Used only when pm is set to 'dynamic'
116 ; Note: Mandatory when pm is set to 'dynamic'
117 pm.min_spare_servers = 1
118
119 ; The desired maximum number of idle server processes.
120 ; Note: Used only when pm is set to 'dynamic'
121 ; Note: Mandatory when pm is set to 'dynamic'
122 pm.max_spare_servers = 3
123
124 ; The number of seconds after which an idle process will be killed.
125 ; Note: Used only when pm is set to 'ondemand'
126 ; Default Value: 10s
127 ;pm.process_idle_timeout = 10s;
128
129 ; The number of requests each child process should execute before respawning.
130 ; This can be useful to work around memory leaks in 3rd party libraries. For
131 ; endless request processing specify '0'. Equivalent to PHP_FCGI_MAX_REQUESTS. 132 ; Default Value: 0
133 ;pm.max_requests = 500
134
135 ; The URI to view the FPM status page. If this value is not set, no URI will be
136 ; recognized as a status page. It shows the following informations:
137 ;  pool                - the name of the pool;
138 ;  process manager      - static, dynamic or ondemand;
139 ;  start time          - the date and time FPM has started;
140 ;  start since          - number of seconds since FPM has started;
141 ;  accepted conn        - the number of request accepted by the pool;
142 ;  listen queue        - the number of request in the queue of pending
143 ;                          connections (see backlog in listen(2));
144 ;  max listen queue    - the maximum number of requests in the queue
145 ;                          of pending connections since FPM has started;
146 ;  listen queue len    - the size of the socket queue of pending connections;
147 ;  idle processes      - the number of idle processes;
148 ;  active processes    - the number of active processes;
149 ;  total processes      - the number of idle + active processes;
150 ;  max active processes - the maximum number of active processes since FPM
151 ;                          has started;
152 ;  max children reached - number of times, the process limit has been reached,
153 ;                          when pm tries to start more children (works only for
154 ;                          pm 'dynamic' and 'ondemand');
155 ; Value are updated in real time.
156 ; Example output:
157 ;  pool:                www
158 ;  process manager:      static
159 ;  start time:          01/Jul/2011:17:53:49 +0200
160 ;  start since:          62636
161 ;  accepted conn:        190460
162 ;  listen queue:        0
163 ;  max listen queue:    1
164 ;  listen queue len:    42
165 ;  idle processes:      4
166 ;  active processes:    11
167 ;  total processes:      15
168 ;  max active processes: 12
169 ;  max children reached: 0
170 ;
171 ; By default the status page output is formatted as text/plain. Passing either 172 ; 'html', 'xml' or 'json'in the query string will return the corresponding
173 ; output syntax. Example:
174 ;  www.foo.bar/status
175 ;  www.foo.bar/status?json
176 ;  www.foo.bar/status?html
177 ;  www.foo.bar/status?xml
178 ;
179 ; By default the status page only outputs short status. Passing 'full'in the
180 ; query string will also return status for each pool process.
181 ; Example:
182 ;  www.foo.bar/status?full
183 ;  www.foo.bar/status?json&full
184 ;  www.foo.bar/status?html&full
185 ;  www.foo.bar/status?xml&full
186 ; The Full status returns for each process:
187 ;  pid                  - the PID of the process;
188 ;  state                - the state of the process (Idle, Running, ...);
189 ;  start time          - the date and time the process has started;
190 ;  start since          - the number of seconds since the process has started;
191 ;  requests            - the number of requests the process has served;
192 ;  request duration    - the duration in µs of the requests;
193 ;  request method      - the request method (GET, POST, ...);
194 ;  request URI          - the request URI with the query string;
195 ;  content length      - the content length of the request (only with POST);
196 ;  user                - the user (PHP_AUTH_USER) (or '-'if not set);
197 ;  script              - the main script called (or '-'if not set);
198 ;  last request cpu    - the %cpu the last request consumed
199 ;                          it's always 0 if the process is not in Idle state
200 ;                          because CPU calculation is done when the request
201 ;                          processing has terminated;
202 ;  last request memory  - the max amount of memory the last request consumed 203 ;                          it's always 0 if the process is not in Idle state
204 ;                          because memory calculation is done when the request
205 ;                          processing has terminated;
206 ; If the process is in Idle state, then informations are related to the
207 ; last request the process has served. Otherwise informations are related to
208 ; the current request being served.
209 ; Example output:
210 ;  ************************
211 ;  pid:                  31330
212 ;  state:                Running
213 ;  start time:          01/Jul/2011:17:53:49 +0200
214 ;  start since:          63087
215 ;  requests:            12808
216 ;  request duration:    1250261
217 ;  request method:      GET
218 ;  request URI:          /test_mem.php?N=10000
219 ;  content length:      0
220 ;  user:                -
221 ;  script:              /home/fat/web/docs/php/test_mem.php
222 ;  last request cpu:    0.00
223 ;  last request memory:  0
224 ;
225 ; Note: There is a real-time FPM status monitoring sample web page available 226 ;      It's available in: /usr/share/php/7.0/fpm/status.html
227 ;
228 ; Note: The value must start with a leading slash (/). The value can be
229 ;      anything, but it may not be a good idea to use the .php extension or it
230 ;      may conflict with a real PHP file.
231 ; Default Value: not set
232 ;pm.status_path = /status
233
234 ; The ping URI to call the monitoring page of FPM. If this value is not set, no 235 ; URI will be recognized as a ping page. This could be used to test from outside 236 ; that FPM is alive and responding, or to
237 ; - create a graph of FPM availability (rrd or such);
238 ; - remove a server from a group if it is not responding (load balancing);
239 ; - trigger alerts for the operating team (24/7).
240 ; Note: The value must start with a leading slash (/). The value can be
241 ;      anything, but it may not be a good idea to use the .php extension or it
242 ;      may conflict with a real PHP file.

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。