Compile nginx under Ubuntu 16.04
·287 字
最近搞了一台N270小主机,性能“还不错”。不过据说编译lnmp要数个小时,于是自己动手安装nginx+php。
首先下载openssl源码
wget https://www.openssl.org/source/openssl-1.1.0c.tar.gz
tar zxvf openssl-1.1.0c.tar.gz
下载nginx:
root@ubuntu:~# wget http://nginx.org/download/nginx-1.11.8.tar.gz
2017-01-06 15:32:38 (38.2 KB/s) - ‘nginx-1.11.8.tar.gz’ saved [964918/964918]
解压,进入目录
root@ubuntu:~# tar zxvf nginx-1.11.8.tar.gz
root@ubuntu:~# cd nginx-1.11.8/
root@ubuntu:~# ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-http_v2_module --with-openssl=../openssl-1.1.0c
checking for getaddrinfo() ... found
checking for PCRE library ... not found
checking for PCRE library in /usr/local/ ... not found
checking for PCRE library in /usr/include/pcre/ ... not found
checking for PCRE library in /usr/pkg/ ... not found
checking for PCRE library in /opt/local/ ... not found
./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.
缺少libpcre,apt安装之。
apt install libpcre3 libpcre3-dev
再次configure:
checking for zlib library ... not found
./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using --with-zlib=<path> option.
缺少zlib,apt安装之
apt install zlib1g-dev
再次configure成功,开始编译
make -j`nproc`
make install
验证安装
root@ubuntu:~# nginx -V
nginx version: nginx/1.11.8
built by gcc 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4)
built with OpenSSL 1.1.0c 10 Nov 2016
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-http_v2_module --with-openssl=../openssl-1.1.0c
安装php:
apt install php7.0-fpm php7.0-curl
更改php-fpm配置文件
编辑/etc/php/7.0/fpm/pool.d/www.conf
文件
listen = /dev/shm/php-cgi.sock
使用临时文件系统,效率更高 重启php-fpm
service php7.0-fpm restart
更改nginx配置文件
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ .*\.php(\/.*)*$ {
include fastcgi.conf;
fastcgi_pass unix:/dev/shm/php-cgi.sock;
}
重启nginx,
killall nginx
nginx
即可使用。
root@ubuntu:~# free -m
total used free shared buff/cache available
Mem: 988 31 487 12 470 914
Swap: 1011 0 1011
仅占用31mb内存。