参考nginx中的办法:
在nginx.conf中,将client_header_buffer_function() { return this.length; }和large_client_header_buffers都调大,可缓解此问题。
其中主要配置是client_header_buffer_function( ) { return this.length; }这一项,默认是1k,所以header小于1k的话是不会出现问题的。
按现在配置:
large_client_header_buffers 4 64k;
参考文档:
http://wiki.nginx.org/NginxHttpCoreModule#client_header_buffer_size
在负载较高时,可以考虑把nginx装一台服务器上,php+mysql装到另一台服务器。
环境描述:
192.168.253.131 php+mysql
一,在129上安装nginx
1,安装pcre,nginx根据正则表达式查询php请求
#cp /lib64/libpcre.so.0 / //在删除系统自带的PCRE之前,要先备份一下libpcre.so.0这个文件,因为RPM包的关联性太强,在删除后没libpcre.so.0这个文件时装PCRE是装不上的
rpm -e --nodeps pcre-6.6-2.el5_1.7 //删除系统自带的PCRE
tar -zxf pcre-7.8.tar.gz
cd pcre-7.8
cp /libpcre.so.0 /lib64/ //把删除系统自带的PCRE之前备份的libpcre.so.0拷贝到/lib 目录下
./configure //配置PCRE,因为PCRE是一个库,而不是像pache、php、postfix等这样的程序,所以安装时选择默认路径即可,这样会在后面安装其它东西时避免一些不必要的麻烦。
make & make install
2,安装nginx
cd nginx-0.7.30
./configure --prefix=/usr/local/nginx //本环节只需指定一个路径
make && make install
二,在31上安装php+mysql
1,安装mysql
useradd mysql
tar zxvf mysql-5.0.40.tar.gz
cd mysql-5.0.40
./configure --prefix=/usr/local/mysql
make && make install
/usr/local/mysql/bin/mysql_install_db --user=mysql //初始化MySQL数据库
chown -R mysql /usr/local/mysql/var
/usr/local/mysql/bin/mysqld_safe & //启动MySQL
/usr/local/mysql/bin/mysqladmin -u root password 123456 //设置MySQL密码
cp support-files/my-medium.cnf /etc/my.cnf
echo "/usr/local/mysql/bin/mysqld_safe &" >>/etc/rc.local
安装php
首先,把PHP和PHP-FPM下载到同一目录下,此次用的为php-5.3.0.tar.bz2和php-5.3.0-fpm-0.5.12.diff.gz,下载到了同一目录下
gzip -cd php-5.3.0-fpm-0.5.12.diff.gz | patch -d php-5.3.0 -p1 //将php-5.3.0-fpm-0.5.12.diff.gz以补丁形式加到php-5.3.0里面
cd php-5.3.0
./configure --prefix=/usr/local/php --enable-fastcgi --enable-fpm --with-mysql=/usr/local/mysql
make && make install
cp php.ini-dist /usr/local/php/etc/php.ini
三,在131上进行配置
修改php-fpm配置文件
1,把127.0.0.1改成本机ip <value name="listen_address">192.168.253.131:9000</value>
2,去掉注释,以nobody用户来运行php
<value name="user">nobody</value>
Unix group of processes
<value name="group">nobody</value>
3,修改客户端ip为192.168.253.129 ,只接受nginx的请求
创建php测试页:
Vim /www/html/index.php
<?php
Phpinfo();
?>
四,配置nginx在192.168.253.129
Vim /usr/local/nginx/conf/nginx/conf
打开CGI部分的注释,修改ip成192.168.253.131 ,并修改php文件的路径为/www/html
root html;
fastcgi_pass 192.168.253.131:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /www/html$fastcgi_script_name;
include fastcgi_params;
}
测试:
http://192.168.253.129/index.php
浏览器中显示存放在131下的测试页面index.php中的内容。
您可能感兴趣的文章:
nginx缓存html静态文件 解析php及反向代理IIS的配置
nginx对静态文件cache的处理机制分析
如何让nginx只缓存静态文件
Nginx 设置静态文件缓存时间
nginx缓存本地静态文件
nginx缓存静态文件的配置方法
nginx rewrite 伪静态配置参数详解
nginx 预压缩(gzip)静态文件
nginx rewrite 伪静态配置参数和使用例子
生产环境中nginx的配置文件nginx.conf:
worker_processes 8;
error_log /data/logs/nginx_error.log crit;
pid /usr/local/webserver/nginx/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535;
events
{
use epoll;
worker_connections 65535;
}
http
{
include mime.types;
default_type application/octet-stream;
#charset gb2312;
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 60;
tcp_nodelay on;
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;
#limit_zone crawler $binary_remote_addr 10m;
server
{
listen 80 default;
server_name _;
index index.html index.htm index.php;
root /data/htdocs/www;
#server_name_in_redirect off;
location ~ .*\.(php|php5)?$
{
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 1h;
}
}
server
{
listen 80;
server_name www.;
index index.html index.htm index.php;
root /data/htdocs/www/adongweb;
#limit_conn crawler 20;
location ~ .*\.(php|php5)?$
{
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 1h;
}
log_format access '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
access_log /data/logs/access.log access;
}
server
{
listen 80;
server_name www.longfeistudio.com;
index index.html index.htm index.php;
root /data/htdocs/www/ImageVue;
#limit_conn crawler 20;
location ~ .*\.(php|php5)?$
{
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 1h;
}
access_log off;
}
server
{
listen 80;
server_name www.hongyanbike.com;
index index.html index.htm index.php;
root /data/htdocs/www/xhui/hybike;
location ~ .*\.(php|php5)?$
{
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 1h;
}
access_log off;
}
server
{
listen 80;
server_name www.very365.com mm.very365.com very365.com;
index index.html index.htm index.php;
root /data/htdocs/www/very365;
location /
{
rewrite ^/(.*)/product/([0-9]+)/$ /seoproduct\.php\?spell=$1&productid=$2;
rewrite ^/brand/(.*)/page/([0-9]+)/$ /seobrand\.php\?spell=$1&page=$2;
rewrite ^/brand/(.*)/$ /seobrand\.php\?spell=$1;
}
location ~ .*\.(php|php5)?$
{
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
fastcgi_param SCRIPT_FILENAME /data/htdocs/www/very365$fastcgi_script_name;
fastcgi_param SCRIPT_NAME /data/htdocs/www/very365$fastcgi_script_name;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 1h;
}
access_log off;
}
server
{
listen 80;
server_name www.wqueen.cn wqueen.cn;
index index.html index.htm index.php;
root /data/htdocs/www/wqueen/bbs;
location ~ .*\.(php|php5)?$
{
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 1h;
}
access_log off;
}
server
{
listen 80;
server_name baobei.wqueen.cn;
index index.html index.htm index.php;
root /data/htdocs/www/baobei;
location ~ .*\.(php|php5)?$
{
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 1h;
}
access_log off;
}
}