本次nginx安装环境为CentOS 7.6、Nginx 1.17.5版本
一.下载与解压
- 本次使用官网下载的nginx-1.17.5.tar.gz压缩包,下载地址:http://nginx.org/download/nginx-1.17.5.tar.gz
- 使用tar命令解压:
tar -zxvf nginx-1.17.5.tar.gz
二.编译及安装
- 进入解压后的nginx目录
cd nginx-1.17.5/- 运行编译命令(此处可能会因为缺少相应的库报错,文章末尾有常见的报错及安装相应的库)
./configure运行成功后显示:
Configuration summary + using system PCRE library + OpenSSL library is not used + using system zlib library nginx path prefix: "/usr/local/nginx" nginx binary file: "/usr/local/nginx/sbin/nginx" nginx modules path: "/usr/local/nginx/modules" nginx configuration prefix: "/usr/local/nginx/conf" nginx configuration file: "/usr/local/nginx/conf/nginx.conf" nginx pid file: "/usr/local/nginx/logs/nginx.pid" nginx error log file: "/usr/local/nginx/logs/error.log" nginx http access log file: "/usr/local/nginx/logs/access.log" nginx http client request body temporary files: "client_body_temp" nginx http proxy temporary files: "proxy_temp" nginx http fastcgi temporary files: "fastcgi_temp" nginx http uwsgi temporary files: "uwsgi_temp" nginx http scgi temporary files: "scgi_temp"运行make命令
make运行成功后显示:
objs/ngx_modules.o \ -ldl -lpthread -lcrypt -lpcre -lz \ -Wl,-E sed -e "s|%%PREFIX%%|/usr/local/nginx|" \ -e "s|%%PID_PATH%%|/usr/local/nginx/logs/nginx.pid|" \ -e "s|%%CONF_PATH%%|/usr/local/nginx/conf/nginx.conf|" \ -e "s|%%ERROR_LOG_PATH%%|/usr/local/nginx/logs/error.log|" \ < man/nginx.8 > objs/nginx.8 make[1]: Leaving directory `/data/nginx-1.17.5'运行make install命令
make install运行成功后显示:
make[1]: Leaving directory `/data/nginx-1.17.5'
至此,nginx已成功安装到/usr/local/nginx目录下,可执行查看
/usr/local/nginx/sbin/nginx -v效果:
[root@VM_0_14_centos nginx]# /usr/local/nginx/sbin/nginx -v
nginx version: nginx/1.17.5编译常见错误:
1 ./configure: error: the HTTP rewrite module requires the PCRE library.
./configure: error: the HTTP rewrite module requires the PCRE library.运行:
yum -y install pcre-devel2 ./configure: error: the HTTP cache module requires md5 functions
from OpenSSL library.
./configure: error: the HTTP cache module requires md5 functions
from OpenSSL library.运行:
yum -y install openssl openssl-devel3 ./configure: error: the HTTP gzip module requires the zlib library.
./configure: error: the HTTP gzip module requires the zlib library.运行:
yum -y install zlib-devel4 You need a C++ compiler for C++ support
You need a C++ compiler for C++ support运行:
yum -y install gcc gcc-c++
版权声明:本文为qq_32523687原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。