nginx| centos7.6中使用yum安装nginx1.6(亲测有效)

 

1.安装依赖

使用nginx源码安装时会使用到gcc等编译工具,系统默认的可能缺少或者版本不对应,因此需要安装或升级一下:

yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel

2.下载Nginx1.6并解压

cd /opt/software
# 下载Nginx的压缩包
wget http://nginx.org/download/nginx-1.16.0.tar.gz
# 解压
tar -xzf nginx-1.16.0.tar.gz

进入到对应的nginx文件中,我这里是/opt/software/nginx-1.16.0.

3.编译安装Nginx

./configure
make
make install

 安装编译过程如下:

[root@VM-12-4-centos nginx-1.16.0]# ./configure
checking for OS
 + Linux 3.10.0-1127.19.1.el7.x86_64 x86_64
checking for C compiler ... found
 + using GNU C compiler
 + gcc version: 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) 
checking for gcc -pipe switch ... found
checking for -Wl,-E switch ... found
..........
creating objs/Makefile

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"

[root@VM-12-4-centos nginx-1.16.0]# make
make -f objs/Makefile
make[1]: Entering directory `/opt/software/nginx-1.16.0'
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
	-o objs/src/core/nginx.o \
	src/core/nginx.c
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I
............. 
src/event -I src/event/modules -I src/os/unix -I objs -I src/http -I src/http/modules \
	-o objs/src/http/modules/ngx_http_upstream_zone_module.o \
	src/http/modules/ngx_http_upstream_zone_module.c
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
	-o objs/ngx_modules.o \
	objs/ngx_modules.c
cc -o objs/nginx \
objs/src/core/nginx.o \
...........
objs/src/http/modules/ngx_http_upstream_keepalive_module.o \
objs/src/http/modules/ngx_http_upstream_zone_module.o \
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 `/opt/software/nginx-1.16.0'
[root@VM-12-4-centos nginx-1.16.0]# make install
make -f objs/Makefile install
make[1]: Entering directory `/opt/software/nginx-1.16.0'
test -d '/usr/local/nginx' || mkdir -p '/usr/local/nginx'
test -d '/usr/local/nginx/sbin' \
	|| mkdir -p '/usr/local/nginx/sbin'
test ! -f '/usr/local/nginx/sbin/nginx' \
	|| mv '/usr/local/nginx/sbin/nginx' \
		'/usr/local/nginx/sbin/nginx.old'
cp objs/nginx '/usr/local/nginx/sbin/nginx'
test -d '/usr/local/nginx/conf' \
	|| mkdir -p '/usr/local/nginx/conf'
cp conf/koi-win '/usr/local/nginx/conf'
cp conf/koi-utf '/usr/local/nginx/conf'
cp conf/win-utf '/usr/local/nginx/conf'
test -f '/usr/local/nginx/conf/mime.types' \
	|| cp conf/mime.types '/usr/local/nginx/conf'
...............
	|| cp -R html '/usr/local/nginx'
test -d '/usr/local/nginx/logs' \
	|| mkdir -p '/usr/local/nginx/logs'
make[1]: Leaving directory `/opt/software/nginx-1.16.0'

过程太长,我删除了中间部分。。。反正结尾就是这个,说明安装完成

4.启动Nginx

安装完后的配置和启动文件放在了/usr/local/nginx中,所以直接cd到那个文件夹中:

# 进入Nginx目录
cd /usr/local/nginx
# 启动nginx
./nginx

这样就启动完成,至于配置项目,就是在/conf/nginx.conf中,具体的配置细节,本文不作介绍。

注:此过程是本人在centos7.6系统中亲测可用的步骤,只要是原版的centos7.6系统没有改动过系统文件的应该都没有问题。在写这篇文章之前本人也是参考了百度各种安装教程,都死在了make install步骤,不知道啥原因(坑啊。。。)。因此,特地写这篇文章来记录一下安装过程, 免得干顿饭后又忘了,也希望可以给大家提供帮助,若大家在安装过程中有其他问题,欢迎在评论区补充~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值