编译安装Nginx

root
233
文章
0
评论
2020年5月19日18:11:47 评论 3367字阅读11分13秒

编译安装Nginx

Nginx官网:http://nginx.org/en/download.html

把源码包下载到linux上

 

#安装PCRE库支持
[root@hwf nginx-1.18.0]# yum -y install pcre-devel pcre
[root@hwf nginx]# wget -c http://nginx.org/download/nginx-1.18.0.tar.gz

[root@hwf nginx]# ll
total 1032
-rw-r--r-- 1 root root 1039530 Apr 21 22:33 nginx-1.18.0.tar.gz

解压压缩包

[root@hwf nginx]# tar -xf nginx-1.18.0.tar.gz 
[root@hwf nginx]# ll
total 1016
drwxr-xr-x 8 xx   project     158 Apr 21 22:09 nginx-1.18.0
-rw-r--r-- 1 root root    1039530 Apr 21 22:33 nginx-1.18.0.tar.gz

#进入解压目录,然后sed修改Nginx版本信息为JWS

[root@hwf nginx]# cd nginx-1.18.0/

[root@hwf nginx-1.18.0]# sed -i -e 's/1.18.0//g' -e 's/nginx\//hewenfu/g' -e 's/"NGINX"/"hewenfu"/g' src/core/nginx.h

创建nginx的系统用户,可以创建别编译的时候指定就行了

[root@hwf nginx-1.18.0]# useradd -M -s /sbin/nologin nginx
[root@hwf nginx-1.18.0]# id nginx
uid=1004(nginx) gid=1005(nginx) groups=1005(nginx)

#预编译Nginx

[root@hwf nginx-1.18.0]# ./configure --prefix=/server/nginx --with-http_dav_module --with-http_stub_status_module --with-http_addition_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module
--with-http_dav_module                  #启用支持(增加PUT,DELETE,MKCOL:创建集合,COPY和MOVE方法)
                                                         默认关闭,需要编译开启
--with-http_stub_status_module    #启用支持(获取Nginx上次启动以来的工作状态)
--with-http_addition_module         #启用支持(作为一个输出过滤器,支持不完全缓冲,分部分相应请求)
--with-http_sub_module                 #启用支持(允许一些其他文本替换Nginx相应中的一些文本)
--with-http_flv_module                   #启用支持(提供支持flv视频文件支持)
--with-http_mp4_module                #启用支持(提供支持mp4视频文件支持,提供伪流媒体服务端支持)

这里预编译的时候提示少什么包,就用yum -y install xxx-devel下载它的开发组包,然后再次输入预编译的命令,再次编译,这样循环,知道它提升成功

#.configure预编译成功后,执行make命令进行编译
make
#make执行成功后,执行make install 正式安装
make install
p conf/nginx.conf '/server/nginx/conf/nginx.conf.default'
test -d '/server/nginx/logs' \
	|| mkdir -p '/server/nginx/logs'
test -d '/server/nginx/logs' \
	|| mkdir -p '/server/nginx/logs'
test -d '/server/nginx/html' \
	|| cp -R html '/server/nginx'
test -d '/server/nginx/logs' \
	|| mkdir -p '/server/nginx/logs'
make[1]: Leaving directory `/server/nginx/nginx-1.18.0'
#至此Nginx WEB服务器安装完毕
[root@hwf nginx]# ll
total 0
drwxr-xr-x 2 root root 333 May 19 17:45 conf
drwxr-xr-x 2 root root  40 May 19 17:45 html
drwxr-xr-x 2 root root   6 May 19 17:45 logs
drwxr-xr-x 2 root root  19 May 19 17:45 sbin

测试Nginx服务安装是否正确,同时启动Nginx WEB 服务,代码命令如下:

/server/nginx/sbin/nginx  -t  检查nginx配置文件是否正确,返回OK即正确。

[root@hwf nginx]# sbin/nginx -t
nginx: the configuration file /server/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /server/nginx/conf/nginx.conf test is successful

然后启动nginx,/usr/local/nginx/sbin/nginx 回车即可。查看进程是否已启动:

[root@hwf nginx]# sbin/nginx
[root@hwf nginx]# ps -ef |grep nginx
root     106044      1  0 18:08 ?        00:00:00 nginx: master process sbin/nginx
nobody   106045 106044  0 18:08 ?        00:00:00 nginx: worker process
root     106055  90822  0 18:09 pts/1    00:00:00 grep --color=auto nginx

通过浏览器访问Nginx默认测试页面,如图所示:

Nginx的升级

Nginx WEB服务器定期更新,如果需要将低版本升级或者将高版本降级,升级或者降级方法如下,分为四个步骤,包括软件下载、预编译、编译、配置,具体方法如下:

获取旧版本nginx的configure选项
/usr/local/nginx/sbin/nginx -V
编译新版本的Nginx
tar  -xvf  nginx-1.4.2.tar.gz
cd nginx-1.4.2
./configure --prefix=/server/nginx --with-http_dav_module --with-http_stub_status_module --with-http_addition_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module --user=www --group=www 
make
备份旧版本的nginx可执行文件,复制新版本的nginx这行文件
mv /usr/local/nginx/sbin/nginx  /usr/local/nginx/sbin/nginx.old
cp objs/nginx /usr/local/nginx/sbin/
测试新版本nginx是否正常
/usr/local/nginx/sbin/nginx -t
平滑重启升级nginx
kill –QUIT `cat /usr/local/nginx/log/nginx.oldbin` ##关闭旧版nginx
验证nginx是否升级成功
/usr/local/nginx/sbin/nginx  -V显示最新编译的版本信息即可。

 

继续阅读
weinxin
我的微信
这是我的微信扫一扫
  • 文本由 发表于 2020年5月19日18:11:47
  • 除非特殊声明,本站文章均为原创,转载请务必保留本文链接
Kafka安装 软件管理

Kafka安装

Kafka安装 kafka定义: kafka是一个分布式的基于发布/订阅模式的消息队列,主要应用于大数据实时处理领域 官网地址:http://kafka.apache.org/ 下载地址:http:/...
VSFTPd 软件管理

VSFTPd

VSFTPd vsFTPd的软件信息 服务端软件名:vsftpd 客户端软件名:ftp 服务名:vsftpd 端口号:20,21,地址范围内随机端口     vsFTP是linux...
匿名

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: