编译nginx的常见错误

a) PCRE library

./configure: error: the HTTP rewrite module requires the PCRE library. You can either disable the module by using –without-http_rewrite_module option, or install the PCRE library into the system, or build the PCRE library statically from the source with nginx by using –with-pcre=<path> option.

apt-get install libpcre3 libpcre3-dev

b) C++ Compiler

configure: error: You need a C++ compiler for C++ support.

apt-get install build-essential

c) OpenSSL

./configure: error: the HTTP cache module requires md5 functions from OpenSSL library.  You can either disable the module by using –without-http-cache option, or install the OpenSSL library into the system, or build the OpenSSL library statically from the source with nginx by using –with-http_ssl_module –with-openssl=<path> options.

./configure: error: SSL modules require the OpenSSL library. You can either do not enable the modules, or install the OpenSSL library into the system, or build the OpenSSL library statically from the source with nginx by using –with-openssl=<path> option.

sudo apt-get install openssl libssl-dev libperl-dev

d) Xml xslt

./configure: error: the HTTP XSLT module requires the libxml2/libxslt libraries. You can either do not enable the module or install the libraries.

apt-get install libxslt-dev

e) GD Library

./configure: error: the HTTP image filter module requires the GD library. You can either do not enable the module or install the libraries.

apt-get install libgd-dev

f) GeoIP Library

./configure: error: the GeoIP module requires the GeoIP library. You can either do not enable the module or install the library.

apt-get install libgeoip-dev

nginx报错accept() failed (24: Too many open files)

查看了一下nginx的error.log日志文件,发现有很多像下面这样的报错:

accept() failed (24: Too many open files)

一看就知道系统对打开文件数目做了限制,用下面命令

ulimit -n    查看当前用户的

命令查看了一下,结果显示文件打开数目限制为1024,我们需要让这个数字更大一些,好让我们的网站访问并发更高一些。

下面是修改 ulimit 限制数的方法:

1.首先你得修改nginx.conf配置文件,在定义error.log日志路径的位置添加一行

worker_rlimit_nofile 65535;

2.在/etc/profile文件最后面添加下面内容

ulimit -n 65535

3.在/etc/security/limits.conf文件最后面添加下面内容

* soft nofile 65535

* hard nofile 65535

*代表所有用户,如果想代表某个用户的话,则user soft nofile 65535

soft代表软连接   hard代表硬限制

查看软限制数量  ulimit -Sn

查看硬限制数量  ulimit -Hn

4.要使 limits.conf 文件配置生效,必须要确保 pam_limits.so 文件被加入到启动文件中

在/etc/pam.d/login 文件最后面添加下面内容

session required /lib/security/pam_limits.so

或者也可以在/etc/profile后面加上ulimit -n 65535

完成上面操作后,再用在退出当前会话,重新登录ulimit -n 查看文件限制数已经被修改为65535了。我再试了一下打开网站,速度快起来了,已经恢复正常了。观察了几分钟,发现nginx日志也没有此类报错信息了。

ubuntu搭建LEMP环境,解决 fpm监听失败

1.安装mysql

  1. sudo apt-get install mysql-server mysql-client

安装过程中要输入root用户的密码。

2.安装nginx

  1. sudo apt-get install nginx

2.安装php

   1.  sudo apt-get install php5-fpm php5-cgi php5-mysql php5-fpm php5-curl php5-gd  php-pear php5-imagick php5-imap  php5-memcache   php5-sqlite php5-tidy php5-mongo

这是常用的扩展

一路安装下来后配置nginx

cd  /etc/nginx/ #配置文件默认在此

通过nginx.conf可以看到引入了 sites-available/文件夹下文件,

vi sites-available/default

可以看到这是本地默认的localhost配置,这就是为什么你在nginx.conf里再加入一个localhost的server  nginx会有waring的原因了,因为它已经定义了。

修改default文件为:

server {
listen 80;
listen [::]:80 default_server ipv6only=on;

root /data/www/;

server_name localhost;

location / {
index index.php index.html index.htm;
}

location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /data/www/$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

location ~ /\.ht {
deny all;
}

}

然后重启nginx和php-fpm

service nginx restart

service php5-fpm restart

在网站根目录编写:

info.php:

<?php

    phpinfo() ;

?>

访问,不成功,查看nginx错误日志,默认是放在/var/log/nginx下

cd /var/log/nginx

tail -fn100  error.log

发现:[error] 15980#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 127.0.0.1, server: localhost, request: “GET /info.php HTTP/1.1”, upstream: “fastcgi://127.0.0.1:9000”, host: “127.0.0.1”

可知是php-fpm的问题

netstat -lnp|grep 9000 (查看9000端口是否被监听)

无内容

解决方法

1 . 按照/etc/php5/fpm/pool.d/www.conf的默认配置使用php5-fpm

# # With php5-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;

2 . 修改/etc/php5/fpm/pool.d/www.conf里的修改为listen=9000

# # With php5-cgi alone:
fastcgi_pass 127.0.0.1:9000;
# # With php5-fpm:
#fastcgi_pass unix:/var/run/php5-fpm.sock;

重启php-fpm