nginx官网有一篇文章专门说明怎么源码编译安装nginx,我们最大限度使用里面的参数,让nginx的特性都开起来.
nginx官网的源码编译说明书
如果需要设置路径,那么就需要自己去下载软件,我们可以看到有两个,分别是zlib和Perl.
下载pcre(跟正则表达式相关)
进入pcre官网:
pcre官网
下载最新版pcre
下载最新版pcre
下载zlib
进入官网:
zlib官网
点击上图下载区域中圈红的地方下载软件
解压pcre
tar -jxvf pcre2-10.23.tar.bz2
解压zlib
tar -zxvf zlib-1.2.11.tar.gz
解压zlib
配置nginx源码
配置nginx源码
配置nginx源码报错
./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.
下载openssl
openssl官网
解压openssl
tar -zxvf openssl-1.1.0e.tar.gz
再次配置nginx源码
./configure --prefix=path=/usr/local/nginx \
--sbin-path=/usr/local/nginx/nginx \
--conf-path=/usr/local/nginx/nginx.conf \
--pid-path=/usr/local/nginx/nginx.pid \
--error-log-path=/usr/local/nginx/logs/error.log \
--http-log-path=/usr/local/nginx/logs/access.log \
--build=nginx \
--user=nginx \
--group=nginx \
--with-select_module \
--with-poll_module \
--with-http_ssl_module \
--with-pcre=/home/test/Desktop/pcre2-10.23 \
--with-pcre-jit \
--with-zlib=/home/test/Desktop/zlib-1.2.11 \
--with-openssl=/home/test/Desktop/openssl-1.1.0e
配置成功:
配置nginx源码成功
make nginx源码
make
make nginx源码报错:
cd /home/test/Desktop/pcre2-10.23 \
&& make libpcre.la
make[2]: Entering directory '/home/test/Desktop/pcre2-10.23'
make[2]: *** No rule to make target 'libpcre.la'. Stop.
make[2]: Leaving directory '/home/test/Desktop/pcre2-10.23'
objs/Makefile:1226: recipe for target '/home/test/Desktop/pcre2-10.23/.libs/libpcre.a' failed
make[1]: *** [/home/test/Desktop/pcre2-10.23/.libs/libpcre.a] Error 2
make[1]: Leaving directory '/home/test/software/nginx-1.12.0'
Makefile:8: recipe for target 'build' failed
make: *** [build] Error 2
make nginx源码报错的原因和解决方案
不能使用pcre2,必须使用pcre1版本,重新下载pcre,现在下载pcre-8.40.tar.gz:
解压:
tar -zxvf pcre-8.40.tar.gz
重新配置nginx源码
./configure --prefix=path=/usr/local/nginx \
--sbin-path=/usr/local/nginx/nginx \
--conf-path=/usr/local/nginx/nginx.conf \
--pid-path=/usr/local/nginx/nginx.pid \
--error-log-path=/usr/local/nginx/logs/error.log \
--http-log-path=/usr/local/nginx/logs/access.log \
--build=nginx \
--user=nginx \
--group=nginx \
--with-select_module \
--with-poll_module \
--with-http_ssl_module \
--with-pcre=/home/test/Desktop/pcre-8.40 \
--with-pcre-jit \
--with-zlib=/home/test/Desktop/zlib-1.2.11 \
--with-openssl=/home/test/Desktop/openssl-1.1.0e
make nginx源码
make
make成功.
安装 nginx
make install
安装成功
创建nologin用户nginx
sudo useradd -s /usr/sbin/nologin -r -M -d /dev/null nginx
修改启动nginx的用户
nginx用的是80端口,在Linux中1024以下的端口号都需要root权限才能使用.
vim /usr/local/nginx/nginx.conf
启动nginx报错
/usr/local/nginx/nginx
报出如下错误:
2017/05/19 02:35:56 [emerg] 10062#0: mkdir() "path=/usr/local/nginx/client_body_temp" failed (2: No such file or directory)
2017/05/19 02:43:11 [emerg] 10510#0: mkdir() "path=/usr/local/nginx/proxy_temp" failed (2: No such file or directory)
2017/05/19 02:43:54 [emerg] 10528#0: mkdir() "path=/usr/local/nginx/fastcgi_temp" failed (2: No such file or directory)
2017/05/19 02:44:16 [emerg] 10551#0: mkdir() "path=/usr/local/nginx/uwsgi_temp" failed (2: No such file or directory)
2017/05/19 02:45:28 [emerg] 10559#0: mkdir() "path=/usr/local/nginx/scgi_temp" failed (2: No such file or directory)
修改
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
client_body_temp_path /usr/local/nginx/client_temp;
proxy_temp_path /usr/local/nginx/proxy_temp;
fastcgi_temp_path /usr/local/nginx/fastcgi_temp;
uwsgi_temp_path /usr/local/nginx/uwsgi_temp;
scgi_temp_path /usr/local/nginx/scgi_temp;
查看nginx是否正常启动
ps -aux|grep nginx
主线程还是root用户启动的,工作线程是使用nginx用户启动
本文暂时没有评论,来添加一个吧(●'◡'●)