源代码编译安装nginx
安装前的准备
- 保证安装编译环境
# yum group list
查看是否有安装Development
没有的话安装Development
# yum group install "Development"
- wget 源代码包
我是在官网上下载的,在http://nginx.org 中找到适合适合CentOS安装的版本。
# wget http://nginx.org/download/nginx-1.4.7.tar.gz
- 解压
# tar xf nginx-1.4.7.tar.gz
进入目录查看帮助信息并安装
# cd nginx-1.4.7
# ./configure --help
# cnfigure --prefix=/usr/local/nginx
- 报错,安装出现问题:
” ./configure: error: the HTTP rewrite module requires the PCRE library.You can either disable the module by using –without-http_rewrite_moduleoption, or install the PCRE library into the system, or build the PCRE librarystatically from the source with nginx by using –with-pcre= option.”
问题是需要PCRE的共享库(library) - 下载,一般这个共享库的命名为:package_name-devel-xxx
# yum install pcre-devel
再次安装
# ./configure --prefix=/usr/local/nginx
- 报错,依旧是共享库的问题:
“./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= option.”
这次是zlib的共享库 - 下载zlib共享库
# yum install zlib-devel
再次安装
# ./configure --prefix=/usr/local/nginx
Configuration summary \+ using system PCRE library \+ OpenSSL library is not used \+ using builtin md5 code \+ sha1 library is not found \+ using system zlib library nginx path prefix: "/usr/local/nginx" nginx binary file: "/usr/local/nginx/sbin/nginx" 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命令必须才./configure所在的目录中执行。 - 安装
# make install
- 启动服务
# /usr/local/nginx/sbin/nginx
- 查看是否启动成功,查看80端口是否被监听。
# netstat -ntlp
安装成功,进入网页查看:http://192.168.98.135
“Welcome to nginx!”