搭建和升级Nginx服务器

在这里插入图片描述
在这里插入图片描述

  • 1 案例1:搭建Nginx服务器

  • 在IP地址为192.168.4.5的主机上安装部署Nginx服务,并可以将Nginx服务器,要求编译时启用如下功能:
    在这里插入图片描述

  • 步骤一:构建Nginx服务器

  • 1)使用源码包安装nginx软件包

[root@svr5 ~]# yum –y install gcc pcre-devel openssl-devel        #安装常见依赖包
[root@svr5 ~]# useradd –s /sbin/nologin nginx
[root@svr5 ~]# tar  -xf   nginx-1.8.0.tar.gz
[root@svr5 ~]# cd  nginx-1.8.0
[root@svr5 nginx-1.8.0]# ./configure   \
> --prefix=/usr/local/nginx   \                #指定安装路径
> --user=nginx   \                            #指定用户
> --group=nginx  \                            #指定组
> --with-http_ssl_module                        #开启SSL加密功能

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"
  
[root@svr5 nginx-1.7.10]# make && make install    #编译并安装
  • 2)nginx命令的用法

[root@svr5 ~]# /usr/local/nginx/sbin/nginx                    #启动服务
[root@svr5 ~]# /usr/local/nginx/sbin/nginx -s stop            #关闭服务
[root@svr5 ~]# /usr/local/nginx/sbin/nginx -s reload        #重新加载配置文件
[root@svr5 ~]# /usr/local/nginx/sbin/nginx –V                #查看软件信息
  • nginx服务默认通过TCP 80端口监听客户端请求:
- [root@svr5 ~]# netstat  -anptu  |  grep 80
tcp        0        0 0.0.0.0:80        0.0.0.0:*        LISTEN        10441/squid
root@psvr5~]# kill 10441     #关闭非nginx 80端口
[root@svr5 ~]# /usr/local/nginx/sbin/nginx                    #重启启动服务

[root@svr5 ~]# netstat  -anptu  |  grep 80
tcp        0        0 0.0.0.0:80        0.0.0.0:*        LISTEN        10441/nginx

  • 3)为Nginx Web服务器建立测试首页文件

  • Nginx Web服务默认首页文档存储目录为/usr/local/nginx/html/,在此目录下建立一个名为index.html的文件:

[root@svr5 ~]# cat  /usr/local/nginx/html/index.html
<html>
<head>
<title>Welcome to nginx!</title>
</head>
<body bgcolor="white" text="black">
<center><h1>Welcome to nginx!</h1></center>
</body>
</html>
  • 步骤二:升级Nginx服务器

  • 1)编译新版本nginx软件

[root@svr5 ~]# tar  -zxvf   nginx-1.9.0.tar.gz
[root@svr5 ~]# cd nginx-1.9.0
[root@svr5 nginx-1.9.0]# ./configure   \
> --prefix=/usr/local/nginx   \ 
> --user=nginx   \ 
> --group=nginx  \ 
> --with-http_ssl_module
[root@svr5 nginx-1.9.0]# make       
  1. 备份老的nginx主程序,并使用编译好的新版本nginx替换老版本
[root@svr5 nginx-1.9.0]# mv /usr/local/nginx/sbin/nginx  \
>/usr/local/nginx/sbin/nginxold
[root@svr5 nginx-1.9.0]# cp objs/nginx  /usr/local/nginx/sbin/    //拷贝新版本
[root@svr5 nginx-1.9.0]# make upgrade                            //升级
/usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`
sleep 1
test -f /usr/local/nginx/logs/nginx.pid.oldbin
kill -QUIT `cat /usr/local/nginx/logs/nginx.pid.oldbin`
[root@svr5 ~]# /usr/local/nginx/sbin/nginx –v                //查看版本

骤三:客户端访问测试

1)分别使用浏览器和命令行工具curl测试服务器页面

[root@client ~]# firefox http://192.168.4.5
[root@client ~]# curl http://192.168.4.5

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值