Nginx 0.8.x + PHP 5.2.13 胜过Apache十倍的Web服务器(第6版)

链接:http://blog.s135.com/nginx_php_v6/

出现的问题

[ERROR] /usr/local/mysql/bin/mysqld: unknown option '--skip-bdb'
有一个默认配置文件在这里/etc/mysql/my.cnf
skip-bdb前加#
 
安装memcache时出现
Cannot find autoconf. Please check your autoconf installation..
解决:apt-get install autoconf
 
/usr/local/webserver/nginx/sbin/nginx: error while loading shared libraries: libpcre.so.0: cannot open shared object file: No such file or directory

安装apt-get install libpcre3-dev
 

在小内存服务器上的配置优化

1、Nginx  的主配置文件(nginx.conf)优化

vi /usr/local/webserver/nginx/conf/nginx.conf

根据下面的内容进行相应的修改和增加

	#Nginx每个进程耗费10M~12M内存,这里只开启一个Nginx进程,节省内存。
worker_processes 1;
#对网页文件、CSS、JS、XML等启动gzip压缩,减少数据传输量,提高访问速度。
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;
location ~ .*\.(php|php5)?$
   {
     #将Nginx与FastCGI的通信方式由TCP改为Unix Socket。TCP在高并发访问下比Unix Socket稳定,但Unix Socket速度要比TCP快。
     fastcgi_pass  unix:/tmp/php-cgi.sock;
     #fastcgi_pass  127.0.0.1:9000;
     fastcgi_index index.php;
     include fcgi.conf;
   }
location ~ /read.php
   {
     #将Nginx与FastCGI的通信方式由TCP改为Unix Socket。TCP在高并发访问下比Unix Socket稳定,但Unix Socket速度要比TCP快。
     fastcgi_pass  unix:/tmp/php-cgi.sock;
     #fastcgi_pass  127.0.0.1:9000;
     fastcgi_index index.php;
     include fcgi.conf;
   }
#博客的图片较多,更改较少,将它们在浏览器本地缓存15天,可以提高下次打开我博客的页面加载速度。
   location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
   {
     expires      15d;
   }
   #博客会加载很多JavaScript、CSS,将它们在浏览器本地缓存1天,访问者在看完一篇文章或一页后,再看另一篇文件或另一页的内容,无需从服务器再次下载相同的JavaScript、CSS,提高了页面显示速度。
   location ~ .*\.(js|css)?$
   {
     expires      1d;
   } 

 

2、PHP(FastCGI)的配置优化
php.ini 配置文件中关于eAcelerator的优化。只使用1M共享内存,删除所有在最后3600秒内无法存取的脚本缓存,用磁盘辅助进行缓存。

vi /usr/local/webserver/php/etc/php.ini

根据内容增加或者修改

eaccelerator.shm_size="1"
eaccelerator.shm_ttl="3600"
eaccelerator.shm_prune_period="3600"
eaccelerator.keys = "disk_only"
eaccelerator.sessions = "disk_only"
eaccelerator.content = "disk_only"

php-fpm.conf 的配置优化

vim /usr/local/webserver/php/etc/php-fpm.conf

一是修改以下一行,将启动的php-cgi进程数由原来的128个改为5个:

<value name="max_children">5</value>

二是修改以下一行,将TCP模式改为Unix Socket模式:

<value name="listen_address">/tmp/php-cgi.sock</value>

3、MySQL配置优化

vi /data0/mysql/3306/my.cnf

根据自己的情况改吧

	[client]
port    = 3306
socket  = /tmp/mysql.sock
[mysql]
prompt="(\u:s135:)[\d]> "
no-auto-rehash
[mysqld]
user    = mysql
port    = 3306
socket  = /tmp/mysql.sock
basedir = /usr/local/webserver/mysql
datadir = /usr/local/webserver/mysql/data
open_files_limit    = 600
back_log = 20
max_connections = 100
max_connect_errors = 200
table_cache = 60
external-locking = FALSE
max_allowed_packet = 16M
sort_buffer_size = 128K
join_buffer_size = 128K
thread_cache_size = 10
thread_concurrency = 8
query_cache_size = 0M
query_cache_limit = 2M
query_cache_min_res_unit = 2k
default_table_type = MyISAM
thread_stack = 192K
transaction_isolation = READ-UNCOMMITTED
tmp_table_size = 512K
max_heap_table_size = 32M
/usr/local/webserver/mysql/data/slow.log
/usr/local/webserver/mysql/data/error.log
long_query_time = 1
log_long_format
server-id = 1
#log-bin = /usr/local/mysql/data/binlog
binlog_cache_size = 2M
max_binlog_cache_size = 4M
max_binlog_size = 512M
expire_logs_days = 7
key_buffer_size = 4M
read_buffer_size = 1M
read_rnd_buffer_size = 2M
bulk_insert_buffer_size = 2M
myisam_sort_buffer_size = 4M
myisam_max_sort_file_size = 10G
myisam_max_extra_sort_file_size = 10G
myisam_repair_threads = 1
myisam_recover
[mysqldump]
quick
max_allowed_packet = 16M

 

如果出现下面的错误提示
checking for xml2-config... no
checking for xml-config... no
configure: error: XML configuration could not be found
安装
apt-get install libxml2-dev
出现
configure: error: Cannot find OpenSSL's <evp.h>
安装
apt-get install libssl-dev
出现
configure: error: Please reinstall the libcurl distribution -
    easy.h should be in <curl-dir>/include/curl/
安装
apt-get install libcurl4-openssl-dev
出现
configure: error: libjpeg.(a|so) not found.
安装
apt-get install libjpeg62-dev
出现
configure: error: libpng.(a|so) not found.
安装
apt-get install libpng12-dev
出现
configure: error: freetype.h not found.
安装
apt-get install libfreetype6-dev
出现
configure: error: sasl.h not found!
安装
apt-get install libsasl2-dev

configure: error: XML configuration could not be found
apt-get install libxml2 libxml2-dev
error: Cannot find OpenSSL <evp.h>
apt-get install libssl-dev
configure: error: Please reinstall the libcurl distribution
apt-get install curl  libcurl4-openssl-dev

****编译php出错的解决方法****
#sudo apt-get install build-essential
不然会出现 checking for C compiler default output file name… configure: error: C compiler cannot create executables
#sudo apt-get install zlib1g-dev
不然 会出现 checking for zlib location… not found
checking whether to enable mod_deflate… configure: error: mod_deflate has been requested but can not be built due to prerequisite failures
error: xml2-config not found. Please check your libxml2 installation.
出现这个时 sudo apt-get install libxml2-dev
error: Cannot find OpenSSL’s
出现这个时 sudo apt-get install libssl-dev
error: Please reinstall the libcurl distribution -easy.h should be in /include/curl/
出现这个时 sudo apt-get install libcurl4-openssl-dev

error: libjpeg.(a|so) not found.
出现这个时 sudo apt-get install libjpeg62-dev
error: libpng.(a|so) not found.
出现这个时 sudo apt-get install libpng12-dev
error: freetype.h not found.
出现这个时 sudo apt-get install libfreetype6-dev

configure: error: sasl.h not found!
apt-get install libsasl2-dev
还没有用到的
error: Unable to find gd.h anywhere
出现这个时 sudo apt-get install libgd2-xpm libgd-tools libgd2-xpm-dev
checking for db4 major version…configure:error:Header contains different version
出现这个时 sudo apt-get install libdb4.6-dev
缺少 libperl-dev 库
/usr/bin/ld: cannot find -lperl
collect2: ld returned 1 exit status
****安装 nginx ********

启动nginx时,提示:error while loading shared libraries: libpcre.so.0: cannot open shared object file: No such file or directory
解决方法,在/lib中创建一个symbol link到/usr/local/lib/libpcre.so.0.1

eAccelerator: Could not allocate 134217728 bytes, the maximum size the kernel allows is 33554432 bytes. Lower the amount of memory request or increase the limit in /proc/sys/kernel/shmmax.
原因是内存分配超出了内核所限定的大小。
shmmax内核参数定义单个共享内存段的最大值。

修改 shmmax 的方法
1.直接修改
echo "2147483648" | sudo tee /proc/sys/kernel/shmmax
echo 0 | sudo tee /proc/sys/vm/vdso_enabled
echo 4096 | sudo tee /proc/sys/vm/mmap_min_addr

2.将以下命令放入 /etc/rc.local 启动文件中:
echo "2147483648" > /proc/sys/kernel/shmmax
echo 0            > /proc/sys/vm/vdso_enabled
echo 4096         > /proc/sys/vm/mmap_min_addr

3.使用 sysctl 命令来更改 SHMMAX 的值:
sysctl -w kernel.shmmax=2147483648

4.内核参数插入到 /etc/sysctl.conf 启动文件中,使这种更改永久有效
echo "kernel.shmmax=2147483648" >> /etc/sysctl.conf

使用命令生效
sudo sysctl –p

502错误

2010/05/21 11:26:16 [crit] 9156#0: *42 connect() to unix:/tmp/php-cgi.sock failed (2: No such file or directory) while connecting to upstream, client: 192.168.0.33, server: localhost, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/tmp/php-cgi.sock:", host: "192.168.0.214:8080"Reply
菜鸟 于 2010-05-26 12:02:46 回复:
和你一样。连报错都一样。。
Reply
gary 于 2010-05-27 10:34:29 回复:
已经自己解决了。
建议LZ贴一下php-fpm.conf文件的主要修为内容。
我是这样做的,找到/etc/php-fpm.conf文件中的 127.0.0.1:9000
将其修改为/tmp/php-cgi.sock
然后重启php-fpm,就ok了

补充:也就是说php-fpm要和nginx配置的一样.

上一篇: 让U盘变成安全的加密便携式绿色软件盘   下一篇: Ubuntu Locale配置问题解决Cannot set LC_CTYPE

提交疑问

回顶部