日期:2014-05-17 浏览次数:20644 次
$ sudo apt-get install python-software-properties
$ sudo add-apt-repository ppa:yola/php5
sudo apt-get update sudo apt-get install php5-fpm
sudo apt-get install nginx

user www-data;
#主动开启cpu多核功能
worker_processes 2;
worker_cpu_affinity 01 10;
#指定nginx进程可以打开的最大文件描述符数量
worker_rlimit_nofile 65535;
pid /var/run/nginx.pid;
events {
#使用epoll的I/O模型
use epoll;
#工作单进程的并发连接数,总体并发连接数 = worker_connections * worker_processes
worker_connections 2048;
#multi_accept在Nginx接到一个新连接通知后调用accept()来接受尽量多的连接
multi_accept on;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
charset utf-8;
server_names_hash_bucket_size 128;
client_header_buffer_size 2k;
large_client_header_buffers 4 4k;
#通过nginx上传文件的大小
client_max_body_size 8m;
#$remote_addr:记录ip地址;$remote_user:记录远程客户端用户名称;$request:请求的url和http协议;$status:用于记录请求状态;$body_bytes_sent:用于记录发送给客户端文件主体内容的大小;$http_referer:跳转链接;$http_x_forwarded_for:客户的真实ip地址
log_format main '$server_name$remote_addr$remote_user[$time_local]"$request"'
'$status$body_bytes_sent"$http_referer"'
'"$http_user_agent""$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
error_log /var/log/nginx/error.log;
sendfile on;
tcp_nopush on;
#keepalive的超时时间
keepalive_timeout 60;
open_file_cache max=204800 inactive=20s;
open_file_cache_min_uses 1;
open_file_cache_valid 30s;
tcp_nodelay on;
gzip on;
include /etc/nginx/conf.d/*.conf;
}
日志格式之间是用不可打印符号进行分隔的,ctrl+v && ctrl+a
upstream haolianxi_php {
server 127.0.0.1:9444;
}
server {
listen 192.168.1.137:7777;
access_log /var/log/nginx/haolianxi/haolianxi.access.log main;
error_log /var/log/nginx/haolianxi/haolianxi.error.log;
#通用匹配
location / {
root /srv/www/php/;
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
access_log /var/log/nginx/haolianxi/location.default.access.log main;
error_log /var/log/nginx/haolianxi/location.default.error.log;
allow 192.168.1.0/24;
deny all;
}
#正则表达式匹配
#proxy the php scripts to php-fpm
location ~ \.php$ {
root /srv/www/php/;
include /etc/nginx/fastcgi_params;
fastcgi_pass haolianxi_php; # The upstream determined above
fastcgi_index index.php;
}
#php-fpm status monitor
location = /phpfpm_status {
fastcgi_pass 127.0.0.1:9444;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
allow 192.168.1.127;
allow 127.0.0.1;
deny all;
}
## Compression
# src: http://www.ruby-forum.com/topic/141251
# src: http://wiki.brightbox.co.uk/docs:nginx
gzip on;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_proxied any;
gzip_min_length 1100;
gzi