FreeBSD 7.3下Nginx+PHP(php-fpm)配置笔记
都说Nginx的性能比Apache NB,找了很多相关的安装资料,终于实现完成了FreeBSD+Nginx+PHP的配置。网上多数Nginx+PHP的配置都是使用的spawn-fcgi,需要额外安装lighttpd或者单独安装spawn-fcgi,其实PHP自带的php-fpm也挺好用的。
一、安装Nginx
# cd /usr/ports/www/nginx
# make install clean
选上自己需要的模块
二、安装PHP
# cd /usr/ports/lang/php52
# make install clean
记得选择FASTCGI和FPM模块
然后安装php52-extensions
# cd /usr/ports/lang/php52-extensions
# make install clean
根据需要选择相关的模块
三、配置php-fpm
# vi /usr/local/etc/php-fpm.conf
根据实际环境修改如下参数:
<value name=”listen_address”>127.0.0.1:9000</value>
<value name=”owner”>www</value>
<value name=”group”>www</value>
<value name=”mode”>0666</value>
<value name=”max_children”>5</value>
<value name=”request_slowlog_timeout”>0s</value>
<value name=”max_requests”>500</value>
四、启动php-fpm
# vi /etc/rc.conf
php_fpm_enable=”YES”
# /usr/local/etc/rc.d/php_fpm start
五、配置Nginx
user www www;
worker_processes 8;
events {
use kqueue;
worker_connections 51200;
}
http {
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 8m;
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
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;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
tcp_nodelay on;
server {
listen 80;
server_name www.bsdart.org;
root /data/web/htdocs;
index index.htm index.html index.php;
location ~ .*\.(php|php5)?$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
五、启动Nginx
# vi /etc/rc.conf
nginx_enable=”YES”
# /usr/local/etc/rc.d/nginx start