CentOS下Nginx编译源码安装-元一软件

发布时间:2026/7/16 5:33:42
CentOS下Nginx编译源码安装-元一软件 本文将简单介绍在CentOS6下面怎样去源码编译安装Nginx。在网上介绍Nginx怎样安装的教程一搜索一大堆为什么还要写这篇博文呢一是为了加深自己的印象二是我安装过程中遇到的问题你可能也会遇到做一个参考也可以啊。源码编译安装主要有五个步骤1下载Nginx源码包如nginx-1.16.1.tar.gz2使用 tar 命令解压源码包3使用 ./configure 命令去自定义我们自己的Nginx指定安装位置等见 ./configure 详解4使用 make 命令去编译源码5使用 make install 安装程序即将程序拷贝到指定的目录使用 tar 命令解压这个你肯定会命令如下[rootS1 ~]# tar -xvzf nginx-1.16.1.tar.gz这里我就没有给出解压的输出信息了。使用 configure 去配置Nginx这里我们不会做太多的配置只使用“–prefixPATH”选项去指定 Nginx 的安装路径。执行命令如下[rootS1 nginx-1.16.1]# ./configure --prefix/root/nginx很不幸遇到了“./configure: error: C compiler cc is not found”问题这是缺少C编译器安装 gcc 即可。如下[rootS1 nginx-1.16.1]# yum install -y gcc继续执行“configure”。又遇到新问题“./configure: error: the HTTP rewrite module requires the PCRE library. ”这是缺少PCRE库安装“pcre-devel”即可。如下[rootS1 nginx-1.16.1]# yum install -y pcre-devel继续执行“configure”。运气很差啊继续遇到新问题“./configure: error: the HTTP gzip module requires the zlib library.”这是缺少HTTP gzip压缩的zlib库安装“zlib-devel”即可如下[rootS1 nginx-1.16.1]# ./configure --prefix/root/nginx这下没有新问题了执行完后面信息如下Configuration summary using system PCRE library OpenSSL library is not used using system zlib library nginx path prefix:/root/nginx# 安装Nginx的基础目录nginx binary file:/root/nginx/sbin/nginx# Nginx二进制文件所在目录nginx modules path:/root/nginx/modules# 模块目录nginx configuration prefix:/root/nginx/conf# 配置目录nginx configuration file:/root/nginx/conf/nginx.confnginx pid file:/root/nginx/logs/nginx.pidnginx error log file:/root/nginx/logs/error.lognginx http access log file:/root/nginx/logs/access.lognginx http client request body temporary files:client_body_tempnginx http proxy temporary files:proxy_tempnginx http fastcgi temporary files:fastcgi_tempnginx http uwsgi temporary files:uwsgi_tempnginx http scgi temporary files:scgi_temp[rootS1 nginx-1.16.1]#成功执行完成后你会发现在Nginx的基础目录下面多出了一个objs目录该目录信息如下rootS1 nginx-1.16.1]# ll objs/total84-rw-r--r--.1root root19575Jul219:15 autoconf.err -rw-r--r--.1root root39934Jul219:15 Makefile -rw-r--r--.1root root6598Jul219:15 ngx_auto_config.h -rw-r--r--.1root root657Jul219:14 ngx_auto_headers.h -rw-r--r--.1root root5856Jul219:15 ngx_modules.c drwxr-xr-x.9root root4096Jul219:15 srcnginx 通过 ngx_auto_headers.h 和 ngx_auto_config.h 动态安装一些模块。使用 make 去编译源码执行“make”命令去编译源码如下[rootS1 nginx-1.16.1]# make再次遇到问题遇到了“-bash: make: command not found”这是因为我们安装CentOS是安装的mini最小系统因为我们需要自己去安装 make。如下[rootS1 nginx-1.16.1]# yum -y install automake autoconf libtool make继续执行 make然后执行 make install。执行成功后进入到 /root/nginx 查看详情如下[rootS1 ~]# cd nginx[rootS1 nginx]# lltotal16drwxr-xr-x.2root root4096Jul219:29 conf drwxr-xr-x.2root root4096Jul219:29 html drwxr-xr-x.2root root4096Jul219:29 logs drwxr-xr-x.2root root4096Jul219:29 sbin然后进入到“sbin”目录运行“./nginx”去启动Nginx服务。然后使用netstat查看端口情况如下[rootS1 nginx]# cd sbin/[rootS1 sbin]# ./nginx[rootS1 sbin]# netstat -ano | grep 80tcp000.0.0.0:800.0.0.0:* LISTEN off(0.00/0/0)