一,php-fpm配置文件的配置
1.清空php-fpm.conf
[global]
pid = /usr/local/php/var/run/php-fpm.pid
error_log = /usr/local/php/var/log/php-fpm.log
[www]
listen = /tmp/php-fcgi.sock
user = php-fpm
group = php-fpm
listen.owner = nobody
listen.group = nobody
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
rlimit_files = 1024
参数说明:
[global]
pid = /usr/local/php/var/run/php-fpm.pid
error_log = /usr/local/php/var/log/php-fpm.log
[www]
listen = /tmp/php-fcgi.sock
user = php-fpm
group = php-fpm
listen.owner = nobody ##此处listen.owner和listen.group一定要设置成nginx的属主属组,不然nginx无法读取
listen.group = nobody
pm = dynamic ##动态、静态子进程pm = dynamic/static,对于专用服务器,pm可以设置成static,这时由pm.max_children指定固定的子进程数
pm.max_children = 50 ##子进程最大数
pm.start_servers = 20 ##启动时的进程数
pm.min_spare_servers = 5 ##保证空闲进程数最小值,如果空闲进程数小于此值,则创建新的子进程
pm.max_spare_servers = 35 ##保证空闲进程数最大值,如果空闲进程数大于此值,则进行清理
pm.max_requests = 500
rlimit_files = 1024
slowlog = /tmp/php_slow.log ##指定慢查询日志的路径
request_slowlog_timeout = 1 ##指定超时时间为1s
php_admin_value[open_basedir]=/data1/www/:/tmp/ ##设置open_basedir
listen = 127.0.0.1:9000 ##可以替代Listen = /tmp/php-fcgi.sock这行
PHP配置文件是用分号注释
[root@KevinLinux tmp]# ll /tmp/php-fcgi.sock
srw-rw---- 1 nobody nobody 0 Jan 16 22:16 /tmp/php-fcgi.sock
二,编辑nginx的配置文件/usr/local/nginx/conf/nginx.conf
user nobody nobody;
worker_processes 2;
error_log /usr/local/nginx/logs/nginx_error.log crit;
pid /usr/local/nginx/logs/nginx.pid;
worker_rlimit_nofile 51200;
events
{
use epoll;
worker_connections 6000;
}
http
{
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 3526;
server_names_hash_max_size 4096;
log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]'
'$host "$request_uri" $status'
'"$http_referer" "$http_user_agent"';
sendfile on;
tcp_nopush on;
keepalive_timeout 30;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
connection_pool_size 256;
client_header_buffer_size 1k;
large_client_header_buffers 8 4k;
request_pool_size 4k;
output_buffers 4 32k;
postpone_output 1460;
client_max_body_size 10m;
client_body_buffer_size 256k;
client_body_temp_path /usr/local/nginx/client_body_temp;
proxy_temp_path /usr/local/nginx/proxy_temp;
fastcgi_temp_path /usr/local/nginx/fastcgi_temp;
fastcgi_intercept_errors on;
tcp_nodelay on;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 8k;
gzip_comp_level 5;
gzip_http_version 1.1;
gzip_types text/plain application/x-javascript text/css text/htm application/xml;
server
{
listen 80 [default_server];
server_name localhost;
index index.html index.htm index.php;
root /usr/local/nginx/html;
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/tmp/php-fcgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
}
}
}
参数说明:
user nobody nobody; ##user是个主模块指令,指定nginx worker进程运行用户和组,默认由nobody账号运行
worker_processes 2; ##主模块指令,指定nginx要开启的进程数。建议指定跟CPU核数相同数量的进程数,每进程平均消耗10~12MB内存
error_log /usr/local/nginx/logs/nginx_error.log crit; ##主模块指令,定义全局错误日志文件。日志级别有debug、info、notice、warn、error、crit。debug最详细
pid /usr/local/nginx/logs/nginx.pid; ##主模块指令,用来指定进程id的存储文件位置
worker_rlimit_nofile 51200; ##用于绑定worker进程和CPU,Linux内核2.4以上可用
events ##event指令用来指定Nginx的工作模式及连接数上限
{
use epoll; ##use是个事件模块指令,用来指定nginx的工作模式:select、poll、kqueue、epoll、rtsig、、dev/poll,Linux系统首选epoll
worker_connections 6000; ##是个事件模块指令,用于定义nginx每个进程的最大连接数,默认1024.
##最大客户端连接数由worker_processes和worker_connections决定,max_client=worker_processes*worker_connections,作为反向代理时,max_client=worker_connections/4
}
http
{
include mime.types; ##这里路径是 conf/mime.types
##include是个主模块指令,实现对配置文件所包含的文件的设定,可以减少主配置文件的复杂度。类似apache中的include方法
default_type application/octet-stream;
##default_type属于HTTP核心模块指令,这里设定默认类型为二进制流,也就是当文件类型未定义时使用这种方式,如:没有配置PHP环境时,nginx是不予解析的,此时浏览器访问PHP文件会出现下载窗口。
server_names_hash_bucket_size 3526;
server_names_hash_max_size 4096;
log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]'
'$host "$request_uri" $status'
'"$http_referer" "$http_user_agent"';
sendfile on; ##开启高效文件传输模式
tcp_nopush on; ##用于防止网络阻塞
keepalive_timeout 30; ##设置客户端连接保持活动的超时时间,超时后服务器会关闭连接
client_header_timeout 3m; ##设置客户端请求头读取超时时间,超时后客户端还没有发送任何数据,nginx将返回Request out(408)错误
client_body_timeout 3m; ##设置客户端请求主体超时时间,默认60,超时将返回Request out(408)错误
send_timeout 3m; ##设置响应客户端超时时间,这个超时仅限于两个连接活动之间的时间,超时客户端仍没有任何活动,Nginx将会关闭连接
connection_pool_size 256;
client_header_buffer_size 1k; ##指定来自客户端请求头的headerbuffer大小。对于大多数请求1KB的缓存区大小已经足够
large_client_header_buffers 8 4k;
request_pool_size 4k;
output_buffers 4 32k;
postpone_output 1460;
client_max_body_size 10m; ##设定允许客户端请求的最大的单个文件字节数
client_body_buffer_size 256k;
client_body_temp_path /usr/local/nginx/client_body_temp;
proxy_temp_path /usr/local/nginx/proxy_temp;
fastcgi_temp_path /usr/local/nginx/fastcgi_temp;
fastcgi_intercept_errors on;
tcp_nodelay on;
gzip on; ##开启gzip模块,实时压缩输出数据流(确保此模块已经加载--with-http_gzip_static_module)
gzip_min_length 1k; ##设置允许压缩的页面最小字节数,默认0不管多大都压缩。建议设置成大于1K的字节数,小于1K可能越压越大
gzip_buffers 4 8k; ##表示申请4个单位为8K的内存作为压缩结果流缓存,默认值是申请与原始数据大小相同的内存空间来存储gzip压缩结果
gzip_comp_level 5; ##指定gzip压缩比,1压缩比最小,处理速度快,9压缩比最大,传输最快,单处理慢,比较消耗CPU资源
gzip_http_version 1.1; ##设置识别HTTP协议版本,默认是1.1,目前大部分浏览器已经支持gzip压缩,使用默认即可
gzip_types text/plain application/x-javascript text/css text/htm application/xml; ##指定压缩类型,无论是否指定,text/html类型都会被压缩
server
##server标志定义虚拟主机开始(建议单独成立一个配置文件,使用include指令加载进来,便于维护、管理)
{
listen 80 [default]; ##指定虚拟主机服务端口,后面接default或者default_server,指定为默认站点
server_name localhost; ##指定IP或域名
index index.html index.htm index.php; ##设定访问的默认地址
root /usr/local/nginx/html; ##root指令用于指定虚拟主机的网页根目录,可以为相对路径、也可以为绝对路径
access_log /usr/local/nginx/logs/access_log combined_realip; ##配置nginx访问日志
location ~ \.php$ { ##URL地址匹配
##通过location指令对网页URL分析处理,.php后缀的文件由nginx处理
include fastcgi_params;
fastcgi_pass unix:/tmp/php-fcgi.sock;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
}
}
}
三,编写nginx启动脚本/etc/init.d/nginx
#!/bin/bash
# chkconfig: - 30 21
# description: http service.
# Source Function Library
. /etc/init.d/functions
# Nginx Settings
NGINX_SBIN="/usr/local/nginx/sbin/nginx"
NGINX_CONF="/usr/local/nginx/conf/nginx.conf"
NGINX_PID="/usr/local/nginx/logs/nginx.pid"
RETVAL=0
prog="Nginx"
start() {
echo -n $"Starting $prog: "
mkdir -p /dev/shm/nginx_temp
daemon $NGINX_SBIN -c $NGINX_CONF
RETVAL=$?
echo
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc -p $NGINX_PID $NGINX_SBIN -TERM
rm -rf /dev/shm/nginx_temp
RETVAL=$?
echo
return $RETVAL
}
reload(){
echo -n $"Reloading $prog: "
killproc -p $NGINX_PID $NGINX_SBIN -HUP
RETVAL=$?
echo
return $RETVAL
}
restart(){
stop
start
}
configtest(){
$NGINX_SBIN -c $NGINX_CONF -t
return 0
}
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
restart
;;
configtest)
configtest
;;
*)
echo $"Usage: $0 {start|stop|reload|restart|configtest}"
RETVAL=1
esac
exit $RETVAL
1.清空php-fpm.conf
[root@KevinLinux ~]# cd /usr/local/php/etc2.编辑php-fpm.conf
[root@KevinLinux etc]# > php-fpm.conf
[global]
pid = /usr/local/php/var/run/php-fpm.pid
error_log = /usr/local/php/var/log/php-fpm.log
[www]
listen = /tmp/php-fcgi.sock
user = php-fpm
group = php-fpm
listen.owner = nobody
listen.group = nobody
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
rlimit_files = 1024
参数说明:
[global]
pid = /usr/local/php/var/run/php-fpm.pid
error_log = /usr/local/php/var/log/php-fpm.log
[www]
listen = /tmp/php-fcgi.sock
user = php-fpm
group = php-fpm
listen.owner = nobody ##此处listen.owner和listen.group一定要设置成nginx的属主属组,不然nginx无法读取
listen.group = nobody
pm = dynamic ##动态、静态子进程pm = dynamic/static,对于专用服务器,pm可以设置成static,这时由pm.max_children指定固定的子进程数
pm.max_children = 50 ##子进程最大数
pm.start_servers = 20 ##启动时的进程数
pm.min_spare_servers = 5 ##保证空闲进程数最小值,如果空闲进程数小于此值,则创建新的子进程
pm.max_spare_servers = 35 ##保证空闲进程数最大值,如果空闲进程数大于此值,则进行清理
pm.max_requests = 500
rlimit_files = 1024
slowlog = /tmp/php_slow.log ##指定慢查询日志的路径
request_slowlog_timeout = 1 ##指定超时时间为1s
php_admin_value[open_basedir]=/data1/www/:/tmp/ ##设置open_basedir
listen = 127.0.0.1:9000 ##可以替代Listen = /tmp/php-fcgi.sock这行
PHP配置文件是用分号注释
[root@KevinLinux tmp]# ll /tmp/php-fcgi.sock
srw-rw---- 1 nobody nobody 0 Jan 16 22:16 /tmp/php-fcgi.sock
二,编辑nginx的配置文件/usr/local/nginx/conf/nginx.conf
user nobody nobody;
worker_processes 2;
error_log /usr/local/nginx/logs/nginx_error.log crit;
pid /usr/local/nginx/logs/nginx.pid;
worker_rlimit_nofile 51200;
events
{
use epoll;
worker_connections 6000;
}
http
{
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 3526;
server_names_hash_max_size 4096;
log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]'
'$host "$request_uri" $status'
'"$http_referer" "$http_user_agent"';
sendfile on;
tcp_nopush on;
keepalive_timeout 30;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
connection_pool_size 256;
client_header_buffer_size 1k;
large_client_header_buffers 8 4k;
request_pool_size 4k;
output_buffers 4 32k;
postpone_output 1460;
client_max_body_size 10m;
client_body_buffer_size 256k;
client_body_temp_path /usr/local/nginx/client_body_temp;
proxy_temp_path /usr/local/nginx/proxy_temp;
fastcgi_temp_path /usr/local/nginx/fastcgi_temp;
fastcgi_intercept_errors on;
tcp_nodelay on;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 8k;
gzip_comp_level 5;
gzip_http_version 1.1;
gzip_types text/plain application/x-javascript text/css text/htm application/xml;
server
{
listen 80 [default_server];
server_name localhost;
index index.html index.htm index.php;
root /usr/local/nginx/html;
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/tmp/php-fcgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
}
}
}
参数说明:
user nobody nobody; ##user是个主模块指令,指定nginx worker进程运行用户和组,默认由nobody账号运行
worker_processes 2; ##主模块指令,指定nginx要开启的进程数。建议指定跟CPU核数相同数量的进程数,每进程平均消耗10~12MB内存
error_log /usr/local/nginx/logs/nginx_error.log crit; ##主模块指令,定义全局错误日志文件。日志级别有debug、info、notice、warn、error、crit。debug最详细
pid /usr/local/nginx/logs/nginx.pid; ##主模块指令,用来指定进程id的存储文件位置
worker_rlimit_nofile 51200; ##用于绑定worker进程和CPU,Linux内核2.4以上可用
events ##event指令用来指定Nginx的工作模式及连接数上限
{
use epoll; ##use是个事件模块指令,用来指定nginx的工作模式:select、poll、kqueue、epoll、rtsig、、dev/poll,Linux系统首选epoll
worker_connections 6000; ##是个事件模块指令,用于定义nginx每个进程的最大连接数,默认1024.
##最大客户端连接数由worker_processes和worker_connections决定,max_client=worker_processes*worker_connections,作为反向代理时,max_client=worker_connections/4
}
http
{
include mime.types; ##这里路径是 conf/mime.types
##include是个主模块指令,实现对配置文件所包含的文件的设定,可以减少主配置文件的复杂度。类似apache中的include方法
default_type application/octet-stream;
##default_type属于HTTP核心模块指令,这里设定默认类型为二进制流,也就是当文件类型未定义时使用这种方式,如:没有配置PHP环境时,nginx是不予解析的,此时浏览器访问PHP文件会出现下载窗口。
server_names_hash_bucket_size 3526;
server_names_hash_max_size 4096;
log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]'
'$host "$request_uri" $status'
'"$http_referer" "$http_user_agent"';
sendfile on; ##开启高效文件传输模式
tcp_nopush on; ##用于防止网络阻塞
keepalive_timeout 30; ##设置客户端连接保持活动的超时时间,超时后服务器会关闭连接
client_header_timeout 3m; ##设置客户端请求头读取超时时间,超时后客户端还没有发送任何数据,nginx将返回Request out(408)错误
client_body_timeout 3m; ##设置客户端请求主体超时时间,默认60,超时将返回Request out(408)错误
send_timeout 3m; ##设置响应客户端超时时间,这个超时仅限于两个连接活动之间的时间,超时客户端仍没有任何活动,Nginx将会关闭连接
connection_pool_size 256;
client_header_buffer_size 1k; ##指定来自客户端请求头的headerbuffer大小。对于大多数请求1KB的缓存区大小已经足够
large_client_header_buffers 8 4k;
request_pool_size 4k;
output_buffers 4 32k;
postpone_output 1460;
client_max_body_size 10m; ##设定允许客户端请求的最大的单个文件字节数
client_body_buffer_size 256k;
client_body_temp_path /usr/local/nginx/client_body_temp;
proxy_temp_path /usr/local/nginx/proxy_temp;
fastcgi_temp_path /usr/local/nginx/fastcgi_temp;
fastcgi_intercept_errors on;
tcp_nodelay on;
gzip on; ##开启gzip模块,实时压缩输出数据流(确保此模块已经加载--with-http_gzip_static_module)
gzip_min_length 1k; ##设置允许压缩的页面最小字节数,默认0不管多大都压缩。建议设置成大于1K的字节数,小于1K可能越压越大
gzip_buffers 4 8k; ##表示申请4个单位为8K的内存作为压缩结果流缓存,默认值是申请与原始数据大小相同的内存空间来存储gzip压缩结果
gzip_comp_level 5; ##指定gzip压缩比,1压缩比最小,处理速度快,9压缩比最大,传输最快,单处理慢,比较消耗CPU资源
gzip_http_version 1.1; ##设置识别HTTP协议版本,默认是1.1,目前大部分浏览器已经支持gzip压缩,使用默认即可
gzip_types text/plain application/x-javascript text/css text/htm application/xml; ##指定压缩类型,无论是否指定,text/html类型都会被压缩
server
##server标志定义虚拟主机开始(建议单独成立一个配置文件,使用include指令加载进来,便于维护、管理)
{
listen 80 [default]; ##指定虚拟主机服务端口,后面接default或者default_server,指定为默认站点
server_name localhost; ##指定IP或域名
index index.html index.htm index.php; ##设定访问的默认地址
root /usr/local/nginx/html; ##root指令用于指定虚拟主机的网页根目录,可以为相对路径、也可以为绝对路径
access_log /usr/local/nginx/logs/access_log combined_realip; ##配置nginx访问日志
location ~ \.php$ { ##URL地址匹配
##通过location指令对网页URL分析处理,.php后缀的文件由nginx处理
include fastcgi_params;
fastcgi_pass unix:/tmp/php-fcgi.sock;
#fastcgi_pass 127.0.0.1:9000; ##此处可以替换上一句fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
}
}
}
三,编写nginx启动脚本/etc/init.d/nginx
#!/bin/bash
# chkconfig: - 30 21
# description: http service.
# Source Function Library
. /etc/init.d/functions
# Nginx Settings
NGINX_SBIN="/usr/local/nginx/sbin/nginx"
NGINX_CONF="/usr/local/nginx/conf/nginx.conf"
NGINX_PID="/usr/local/nginx/logs/nginx.pid"
RETVAL=0
prog="Nginx"
start() {
echo -n $"Starting $prog: "
mkdir -p /dev/shm/nginx_temp
daemon $NGINX_SBIN -c $NGINX_CONF
RETVAL=$?
echo
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc -p $NGINX_PID $NGINX_SBIN -TERM
rm -rf /dev/shm/nginx_temp
RETVAL=$?
echo
return $RETVAL
}
reload(){
echo -n $"Reloading $prog: "
killproc -p $NGINX_PID $NGINX_SBIN -HUP
RETVAL=$?
echo
return $RETVAL
}
restart(){
stop
start
}
configtest(){
$NGINX_SBIN -c $NGINX_CONF -t
return 0
}
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
restart
;;
configtest)
configtest
;;
*)
echo $"Usage: $0 {start|stop|reload|restart|configtest}"
RETVAL=1
esac
exit $RETVAL
编辑回复