设为首页 收藏本站
查看: 961|回复: 0

[经验分享] nginx升级及遇到的问题

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2018-11-8 08:31:06 | 显示全部楼层 |阅读模式
  Nginx于11月20日通过官方邮件列表更新了一个安全漏洞,该漏洞影响Nginx 0.8.41 至 1.5.6版本,***者可以通过该漏洞绕过Nginx的部分访问策略控制或通过上传功能向服务器植入后门。
  漏洞描述
  当***通过例如下列方式进行 URL 访问限制的时候,如果***者使用一些没经过转义的空格字符(无效的 HTTP 协议,但从 Nginx 0.8.41 开始因为考虑兼容性的问题予以支持)那么这个限制可能无效:
  location /protected/ {
  deny all;
  }
  当请求是 "/foo /../protected/file" 这样的 URL (静态文件,但 foo 后面有一个空格结尾) 或者是如下的配置时:
  location ~ \.php$ {
  fastcgi_pass ...
  }
  当***者请求 "/file \0.php" 时就会绕过限制。
  该问题已经在 Nginx 1.5.7 和 1.4.4 版本中修复。
  修复方式
  1:源码方式: Nginx官方已经更新该漏洞的源码补丁,请通过更新源码来修复。补丁地址:http://nginx.org/download/patch.2013.space.txt
  2:升级Nginx:将Nginx升级到1.5.7和1.4.4版本
  3:临时补丁:在配置中添加以下规则,来禁止带有空格字符的访问。
  if ($request_uri ~ " ") {
  return 444;
  }
  --------------------------------------------------
  安全漏洞处理指南:常见漏洞处理指南应用安全漏洞检查项及常见漏洞修复方案常见漏洞培训视频
  安全配置及开发指南:http://security.sohu-inc.com/zhidu.php
  平滑升级完全参照张宴的nginx书操作,之前需要查看现有nginx版本、编译安装的参数、进程数据等;
  查看版本、编译参数:
  [root@test shell]# /usr/local/nginx/sbin/nginx -V
  nginx version: nginx/1.2.7
  built by gcc 4.1.2 20080704 (Red Hat 4.1.2-54)
  TLS SNI support disabled
  configure arguments: --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module
  进程数据:
  [root@test shell]# ps -ef |egrep -egrep|egrep nginx
  root    14859    1  0 Oct22 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
  appusr  16499 14859  0 Oct22 ?        00:00:00 nginx: worker process
  appusr  16500 14859  0 Oct22 ?        00:00:00 nginx: worker process
  appusr  16501 14859  0 Oct22 ?        00:00:00 nginx: worker process
  appusr  16502 14859  0 Oct22 ?        00:00:00 nginx: worker process
  下面进行平滑升级操作:
  1、下载想要升级nginx版本,然后编译覆盖安装(默认新的nginx将继续安装在旧的nginx目录下)。为了体现出升级的不同我在编译时还增加了关于user、group的定义。
  wget http://nginx.org/download/nginx-1.5.6.tar.gz
  tar -zvxf nginx-1.5.6.tar.gz
  cd nginx-1.5.6
  ./configure --user=appusr --group=appusr --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module  && make && make install
  2、执行
  [root@test nginx-1.5.6]# kill -USR2 14859  【老版本的Nginx主进程号】
  3、旧版本 nginx 的主进程将重命名它的 pid 文件例如 .oldbin(如:/usr/local/nginx/logs/nginx.pid.oldbin)
  4、此时,新旧两个版本的nginx进程都在运行中(默认,新版本的nginx在安装后就自动运行。)此时运行 kill -WINCH 【老版本的Nginx主进程号】 使老版本的nginx 的worker process 逐步结束;
  [root@test shell]# kill -WINCH 14859
  [root@test shell]# ps -ef |egrep nginx
  root      4906 14859  0 11:19 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
  appusr    4907  4906  6 11:19 ?        00:00:04 nginx: worker process
  appusr    4908  4906  6 11:19 ?        00:00:04 nginx: worker process
  appusr    4909  4906  3 11:19 ?        00:00:02 nginx: worker process
  appusr    4910  4906  6 11:19 ?        00:00:04 nginx: worker process
  root      4978 29465  0 11:20 pts/0    00:00:00 egrep nginx
  root    14859    1  0 Oct22 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
  appusr  16499 14859  0 Oct22 ?        00:00:25 nginx: worker process is shutting down
  appusr  16500 14859  0 Oct22 ?        00:00:27 nginx: worker process is shutting down
  appusr  16502 14859  0 Oct22 ?        00:00:27 nginx: worker process is shutting down
  可以看到nginx: worker process isshutting down,说明老版本的nginx worker process正在逐步关闭。
  批量升级时,也可以制作成rpm包,放到yum源,附脚本
for i in `cat host.gti`;do ssh ${i} bash < nginx_bak.sh;done  #!/bin/bash
  source /etc/profile
  DATE=`date "+%Y%m%d-%H%M%S"`;
  BACKUP_DIR="/opt/backup/nginx/${DATE}"
  PID=`ps -ef | grep nginx | grep root | grep -v grep | awk '{print $2}'`
  TEMP_DIR=`mktemp -u`
  mkdir -p ${BACKUP_DIR}
  /bin/cp -r -p /usr/local/nginx ${BACKUP_DIR}
  mkdir ${TEMP_DIR}
  /bin/cp -r -p /usr/local/nginx/conf ${TEMP_DIR}/
  yum clean all
  yum install nginx-1.4.4-2 -y
  /bin/cp -r -p ${TEMP_DIR}/conf /usr/local/nginx/
  echo ${PID}
  kill -USR2 ${PID} && sleep 3 && kill -WINCH ${PID}
  ps -ef | grep nginx | grep -v 'grep'
  #kill -QUIT ${PID}
  下面是我遇到的问题:
  1、configure时没有报错,make时碰到如下错误
error: ‘ngx_connection_t’ has no member named ‘single_connection’  /opt/soft/wiznmp/srchttp://blog.51cto.com/e/u/themes/default/images/spacer.gifaoslawful-lua-nginx-module-7ee528b/srchttp://blog.51cto.com/e/u/themes/default/images/spacer.gifx_http_lua_socket_tcp.c: In function ‘ngx_http_lua_socket_tcp_connect’:
  /opt/soft/wiznmp/srchttp://blog.51cto.com/e/u/themes/default/images/spacer.gifaoslawful-lua-nginx-module-7ee528b/srchttp://blog.51cto.com/e/u/themes/default/images/spacer.gifx_http_lua_socket_tcp.c:445: error: ‘ngx_connection_t’ has no member named ‘single_connection’
  make[1]: *** [objs/addon/srchttp://blog.51cto.com/e/u/themes/default/images/spacer.gifx_http_lua_socket_tcp.o] Error 1
  make[1]: Leaving directory `/roothttp://blog.51cto.com/e/u/themes/default/images/spacer.gifinx-1.4.4'
  make: *** [build] Error 2
  原因:是因为我的lua模块版本较旧,下载新版本即可,下载最新的 lua-nginx-module(在这个页面找:https://github.com/chaoslawful/lua-nginx-module/tags)
  2、启动nginx时,报如下错误
  unknown directive "set_real_ip_from" in /usr/local/nginx/conf/nginx.conf:5
  原因:由于我以前添加过新的参数,而/usr/local/nginx/sbin/nginx -V没有显示我后来添加的模块,所以我升级时是按照查询出来的参数直接配置的,忘记了后来添加的参数,从新配置添加上 --with-http_realip_module


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.iyunv.com/thread-632165-1-1.html 上篇帖子: nginx+resin session 问题解决 下篇帖子: nginx logformat
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表