实用的升级安装方法php,Nginx,mysql,zabbix等

升级版本编译安装当然Ok,依赖问题处理起来非常之繁琐,现在直接通过apt源来升级版本非常简便,下面我们来拿php做个升级实验

1. 添加下面两行到/etc/apt/sources.list,并将jessie替换为自己所使用的版本名称:

deb http://mirrors.ustc.edu.cn/dotdeb jessie all
deb-src http://mirrors.ustc.edu.cn/dotdeb jessie all

2. 可选项:

如果你想在Debian Squeeze上安装PHP5.4的话,再添加下面这两行:

deb http://mirrors.ustc.edu.cn/dotdeb squeeze-php54 all
deb-src http://mirrors.ustc.edu.cn/dotdeb squeeze-php54 all

如果你想在Debian Wheezy上安装未启用Zend Thread Safety的PHP5.6的话,再添加下面这两行:

deb http://mirrors.ustc.edu.cn/dotdeb wheezy-php56 all
deb-src http://mirrors.ustc.edu.cn/dotdeb wheezy-php56 all

如果你想在Debian Wheezy上安装启用Zend Thread Safety的PHP5.6的话,再添加下面这两行:

deb http://mirrors.ustc.edu.cn/dotdeb wheezy-php56-zts all
deb-src http://mirrors.ustc.edu.cn/dotdeb wheezy-php56-zts all

如果你想在Debian Wheezy上安装PHP5.5的话,再添加下面这两行:

deb http://mirrors.ustc.edu.cn/dotdeb wheezy-php55 all
deb-src http://mirrors.ustc.edu.cn/dotdeb wheezy-php55 all

3. 然后导入合适的GnuPG key

wget https://www.dotdeb.org/dotdeb.gpg
cat dotdeb.gpg | sudo apt-key add -

4. 运行

apt-get update

升级php例子:

升级前

一系列操作

401 2017-10-21 09:25:26 echo “deb http://packages.dotdeb.org wheezy-php56 all” >> /etc/apt/sources.list.d/dotdeb.list
402 2017-10-21 09:25:32 echo “deb-src http://packages.dotdeb.org wheezy-php56 all” >> /etc/apt/sources.list.d/dotdeb.list
403 2017-10-21 09:25:39 wget http://www.dotdeb.org/dotdeb.gpg -O- | apt-key add –
405 2017-10-21 09:26:17 dpkg -l |grep php
413 2017-10-21 09:28:30 for pkg in `dpkg -l |grep php |awk ‘{print $2}’`;do dpkg -P $pkg; done
425 2017-10-21 09:29:28 aptitude update
426 2017-10-21 09:29:46 aptitude install php5-fpm php5-cgi php5-cli php5-curl php5-gd php5-mcrypt php5-mysql php5-memcache php5-xmlrpc php5-dev libapache2-mod-php5

然后看看升级后的版本

未分类

ok升级完成,类似nginx等都可以参考这个方法。

nginx和php-fpm连接超时之解决方法

前言

现在线上系统的架构大致是这样的,除去cache的proxy机器外,还有项目的nginx proxy机器,后面跟nginx webserver + php-fpm。有时候,会看到proxy nginx的日志里面会有各种异常状态码,比如499,502,504等,这些都是什么情况导致的呢?

架构示意

nginx proxy => nginx webserver => php-fpm

状态码说明

499:客户端(或者proxy)主动断开连jie502:网关错误(Bad Gateway)504:网关超时:(Gateway Timeout)

一、proxy和webserver不能连接

1.1 proxy_pass ip不存在

这时候会重复发送arp解析协议,约3秒后超时,proxy返回码为502。

1.2 proxy_pass ip存在

  • webserver机器上端口上没有对应服务;

webserver所在机器的内核会直接返回RESET包,没有额外超时,proxy返回码为502。

  • webserver机器端口上有服务,但是iptables DROP了proxy的包;

因为webserver drop(iptables -I INPUT -s xxx.xxx.xxx.xxx -j DROP)了proxy的包,proxy会TCP连接不断重试,默认会重试60秒后proxy返回码504,这个重试时间60秒由参数proxy_connect_timeout指定,重试间隔就是TCP的重试间隔(1,2,4…)。

如果在超时之前,客户端主动关闭连接(比如停止浏览器的请求),这个时候proxy会记录 499状态码,而且$request_time
记录的是proxy已经处理的时间,而$upstream_response_time为-。客户端主动关闭后,proxy也不会再向webserver发送重试请求。

但是如果你在proxy配置了proxy_ignore_client_abort on,那么即便客户端主动关闭,proxy还是会不停的发送重试请求到webserver,直至超时,记录的状态码为webserver返回的状态码。

  • webserver机器端口有服务,但是iptables reject了proxy的包。

因为webserver reject(iptables -I INPUT -s xxx.xxx.xxx.xxx -j REJECT)了proxy的包,与drop不同之处在于,这个时候webserver会返回一个端口不可达的ICMP包给proxy,proxy会重试一次后返回 502 给客户端,超时时间约为1秒。

二、proxy和webserver连接正常(请求时间过长)

proxy的nginx.conf中的proxy_read_timeout=60webserver的nginx.conf中fastcgi_read_timeout=300php-fpm中的 request_terminate_timeout=120

未分类

nginx.conf配置文件

2.1 php执行时间超过proxy的proxy_read_timeout:

假设php-fpm有一个test.php执行时间为100秒,超过了默认的proxy_read_timeout=60,则到1分钟后proxy会关闭到webserver的连接,webserver记录的返回码为499,proxy的返回码为 504,客户端看到的返回码也就是 504。

关于proxy_read_timeout要多说一句,在nginx文档中可以看到这个参数的含义是:

The timeout is set only between two successive read operations,not for the transmission of the whole response.

意思是说并非response的传输超时,而是两次读操作之间的间隔超时。比如在proxy中设置proxy_read_timeout=10,而测试的test.php 如下:

<?phpsleep(7);echo "haha";ob_flush();flush();sleep(7);echo "haha after 7s";?>

这整个请求的响应时间是14秒,其实是不会超时的,因为相邻两次读操作的间隔是7秒小于10秒。注意代码中的ob_flush()
和flush()两个函数,其中ob_flush()是为了刷php的缓存,flush()则是为了刷系统层面的缓存。将/etc/php5/fpm/php.ini中设置output_buffering=off,则可以不用调用ob_flush()了,但是flush()还是需要的。如果不flush的话,php会等到整个响应完成才会将数据返回给webserver,webserver再返回给proxy,在没有返回整个响应之前(14秒才能返回),超过了 proxy_read_timeout的10秒,此时,proxy会关闭和webserver的连接,导致出现504错误。为了这个测试test.php不超时,webserver的nginx还要加一个配置fastcgi_buffering off,因为虽然我们的php返回了数据了,但是webserver的nginx还是缓存了fastcgi的返回,导致没有及时将数据返回给proxy,从而超时。

未分类

php.ini文件

在如上面配置好后,可以发现,浏览器输出了hahahaha after 7s那么问题来了,这两个字符串是同时输出的,并没有像代码中那样隔了7秒,那这个问题是什么导致的呢?答案是proxy的nginx也有缓存配置,需要关闭才能看到先后输出两个字符串的效果。nginx proxy的缓存配置为proxy_buffering off,这样你就能看到先后输出两个字符串的效果了。

2.2 php执行时间超过webserver的fastcgi_read_timeout

设置fastcgi_read_timeout=10,test.php执行时间100秒,则10秒后webserver会关闭和PHP的连接,webserver记录日志的返回码为 504,proxy日志的返回码也是 504。

2.3 php执行时间超过php-fpm的request_terminate_timeout

设置request_terminate_timeout=5,test.php还是执行100秒,可以发现5秒之后,php-fpm会终止对应的php子进程,webserver日志的状态码为 404,proxy的日志的状态码也是 404。

注:经测试,在php-fpm模式中,php.ini中的max_execution_time参数没有什么效果。

三、关于文件数问题

Linux里面的一些限制参数可以通过ulimit -a查看,比如我的debian8.2系统的输出如下:

# ulimit -acore file size (blocks, -c) 0data seg size (kbytes, -d) unlimitedscheduling priority (-e) 0file size (blocks, -f) unlimitedpending signals (-i) 96537max locked memory (kbytes, -l) 64max memory size (kbytes, -m) unlimitedopen files (-n) 1000000pipe size (512 bytes, -p) 8POSIX message queues (bytes, -q) 819200real-time priority (-r) 0stack size (kbytes, -s) 8192cpu time (seconds, -t) unlimitedmax user processes (-u) 96537virtual memory (kbytes, -v) unlimitedfile locks (-x) unlimited

其中open files是一个进程可以同时打开的文件数,超过则会报too many open files错误,修改可以通过ulimit -n xxx来实现。而max user processes则是用户最多创建的进程数。

另外,系统允许打开的最大文件数在配置file-max中。

# cat /proc/sys/fs/file-max2471221

修改file-max可以通过# sysctl -w fs.file-max=1000000修改,永久生效需要在/etc/sysctl.conf中加入这行fs.file-max=1000000然后sysctl -p即可。

要针对用户限制文件数之类的,可以修改/etc/security/limits.conf,内容格式如下:

<domain> <type> <item> <value>## 比如限制 bob这个用户的一个进程同时打开的文件数## Example hard limit for max opened filesbob hard nofile 4096## Example soft limit for max opened filesbob soft nofile 1024

nginx配置中的worker_rlimit_nofile可以配置为open files这个值。

未分类

ulimit -a命令

未分类

sysctl.conf文件

nginx upstream 容错解决“nginx upstream timed out”错误

未分类

有相关人员在调查在服务器日志中发现的有关nginx错误:

Upstream timed out (110: Connection timed out) while reading response header from upstream

这个nginx超时错误位于一个nginx – apache代理服务器中nginx upstream 容错,其中nginx服务所有静态内容和apache所有动态。

Nginx Upstream Timed Out方案

调查错误,并尝试了一些修复后,发现这个错误可能会发生在两种情况:

1)Nginx作为代理

尝试在proxy_read_timeout虚拟主机配置中添加选项,应该如下所示:

nginx upstream 高可用proxy_read_timeout 150;

将其放置在您的根位置配置中:

位置 / {

proxy_read_timeout 150;

}

2)Nginx作为具有php-fpm或其他应用程序的独立服务器。

如果是这种情况,请尝试添加fastcgi_read_timeout选项:

fastcgi_read_timeout 150;

使用php-fpm配置,应该如下所示:

nginx cache位置?* .php $ {

包括fastcgi_params;

fastcgi_index index.php

fastcgi_read_timeout 150;

fastcgi_pass 127.0.0.1:9000;

fastcgi_param _FILENAME $ document_root $ fastcgi__name;

}

在这两种情况下,只需重新启动nginx即可应用更改。

GDCA一直以“构建网络信任体系,服务现代数字生活”的宗旨,致力于提供全球化的数字证书认证服务。其自主品牌——信鉴易?TrustAUTHSSL证书系列,为涉足互联网的企业打造更安全的生态环境,建立更具公信力的企业网站形象。

CentOS 7:使用HAProxy实现Nginx负载均衡

HAProxy是一款功能强大、灵活好用的反向代理的开源软件,它提供了负载均衡、服务器代理的功能。HAProxy是Willy Tarreau使用C语言编写的,它支持SSL、压缩、keep-alive、自定义日志格式和header重写。

HAProxy是轻量级的负载均衡和代理服务软件,占用系统资源较少。很多大型的网站都在使用它,例如Github、StackOverflow。

下面我安装配置HAProxy做为两个Nginx服务器的负载均衡。一共需要使用3个服务器,在一台机器上安装HAProxy,另两台机器安装Nginx服务。

未分类

HAProxy的基本概念

4层和7层

HAProxy可以使用两种模式运行:TCP 4层模式和HTTP 7层模式。TCP模式:HAProxy把原始TCP数据包从客户端转向到应用服务器;HTTP模式:解析http请求,然后转向到web服务器。我们将使用HTTP 7层模式。

负载均衡算法

HAProxy使用负载均衡算法决定把请求发送给哪个服务器,使用的算法:
Roundrobin-轮流算法
这是最简单的负载均衡算法。对每个新连接,总是下一个后端服务器处理。如果到达最后一个后端服务器,从头开始。

Lastconn

有最少连接的后端服务器处理新请求。当请求量较大时非常好。

Source

根据客户端IP决定哪个后端服务器处理。如果IP1是server1处理,那么这个IP1的所有请求都由server1处理。根据IP地址的哈希值决定后端服务器。

系统要求

3个CentOS 7服务器:

  • 处理负载均衡的HAProxy服务器:192.168.0.101

  • Nginx1服务器:192.168.0.108

  • Nginx2服务器:192.168.0.109

第一步

编辑HAProxy服务器(102.168.0.101)的/etc/hosts:

vim /etc/hosts

添加Nginx1和Nginx2的主机名:

192.168.0.108    nginx1.your_domain.com     nginx1
192.168.0.109    nginx2.your_domain.com     nginx2

保存退出。

同样,编辑两个Nginx服务器的/etc/hosts,添加:

192.168.0.101    loadbalancer

在两个Nginx服务器上都要设置。

第二步

在HAProxy服务器上安装HAProxy:

# yum update
# yum install haproxy

haproxy的配置文件位于/etc/haproxy/。为了防止出错,先备份原始配置文件:

# cd /etc/haproxy/
# mv haproxy.cfg haproxy.cfg.backup

编辑配置文件:

# vim haproxy.cfg

写入如下内容:

#---------------------------------------------------------------------
# 全局设置
#---------------------------------------------------------------------
global
log         127.0.0.1 local2     # 日志
chroot      /var/lib/haproxy
pidfile     /var/run/haproxy.pid
maxconn     4000                
user        haproxy             # Haproxy在haproxy用户和组下运行
group       haproxy
daemon
# 开启 stats unix socket
stats socket /var/lib/haproxy/stats
#---------------------------------------------------------------------
# 基本设置
#---------------------------------------------------------------------
defaults
mode                    http
log                     global
option                  httplog
option                  dontlognull
option http-server-close
option forwardfor       except 127.0.0.0/8
option                  redispatch
retries                 3
timeout http-request    10s
timeout queue           1m
timeout connect         10s
timeout client          1m
timeout server          1m
timeout http-keep-alive 10s
timeout check           10s
maxconn                 3000
#---------------------------------------------------------------------
# HAProxy Monitoring 配置
#---------------------------------------------------------------------
listen haproxy3-monitoring *:8080                # Haproxy Monitoring 的使用端口:8080
mode http
option forwardfor
option httpclose
stats enable
stats show-legends
stats refresh 5s
stats uri /stats                            # HAProxy monitoring的网址
stats realm Haproxy Statistics
stats auth testuser:test1234                # 登录Monitoring的用户和密码
stats admin if TRUE
default_backend app-main
#---------------------------------------------------------------------
# FrontEnd 配置
#---------------------------------------------------------------------
frontend main
bind *:80
option http-server-close
option forwardfor
default_backend app-main
#---------------------------------------------------------------------
# 使用roundrobin做为负载均衡算法
#---------------------------------------------------------------------
backend app-main
balance roundrobin                                    # 使用的负载均衡算法
option httpchk HEAD / HTTP/1.1rnHost: localhost    # 检查nginx服务器是否连通- 200状态码
server nginx1 192.168.0.108:80 check                  # Nginx1 
server nginx2 192.168.0.109:80 check                  # Nginx2
配置rsyslog

我们需要使用rsyslog记录HAProxy的日志,编辑rsyslog.conf配置文件,打开UDP的514端口:

# vim /etc/rsyslog.conf

去掉如下行的注释:

$ModLoad imudp
$UDPServerRun 514

如果你想指定特定IP,可以更改如下行:

$UDPServerAddress 127.0.0.1

保存退出。

创建rsyslog配置文件:

# vim /etc/rsyslog.d/haproxy.conf

写入如下内容:

local2.=info     /var/log/haproxy-access.log    # 访问日志
local2.notice    /var/log/haproxy-info.log      # haproxy执行信息

重启rsyslog:

# systemctl restart rsyslog

启动HAProxy:

# systemctl start haproxy
# systemctl enable haproxy

第三步

安装配置Nginx。

Nginx1和Nginx2服务器配置方法相同。

安装epel-release:

# yum install epel-release

安装Nginx:

# yum install nginx

创建index.html测试文件,Nginx1(192.168.0.108):

# cd /usr/share/nginx/html/
# echo "<h1>nginx1.your_domain.com</h1>" > index.html
Nginx2(192.168.0.109):
# cd /usr/share/nginx/html/
# echo "<h1>nginx2.your_domain.com</h1>" > index.html

启动Nginx服务:

# systemctl enable nginx
# systemctl start nginx

测试

测试nginx1、2,使用浏览器访问:

192.168.0.108
192.168.0.109

正常访问网站:http://192.168.0.101,如果有域名,指向这个IP。
登录HAProxy web管理页面:

http://192.168.0.101:8080/stats

你应该可以看到nginx、http请求的转发信息。

nginx使用nginx-rtmp-module模块实现直播间功能

系统环境

wujianjun@wujianjun-work ~ $ uname -a
Linux wujianjun-work 4.10.0-37-generic #41~16.04.1-Ubuntu SMP Fri Oct 6 22:42:59 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

软件环境

  • OBS(Open Broadcaster Software) v20.0.1 (Linux)

  • nginx version: nginx/1.13.6

  • built by gcc 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.5)

  • built with OpenSSL 1.0.2g 1 Mar 2016

  • TLS SNI support enabled

  • configure arguments: Cwith-pcre=pcre-8.38 Cadd-module=nginx-rtmp-module-1.1.11

Nginx+obs安装及配置 安装obs

wujianjun@wujianjun-work ~ $ sudo add-apt-repository ppa:kirillshkrogalev/ffmpeg-next
wujianjun@wujianjun-work ~ $ sudo apt-get update && sudo apt-get install ffmpeg
wujianjun@wujianjun-work ~ $ sudo apt-get install obs-studio
wujianjun@wujianjun-work ~ $ sudo add-apt-repository ppa:obsproject/obs-studio
wujianjun@wujianjun-work ~ $ sudo apt-get update && sudo apt-get install obs-studio

nginx加装rtmp模块

nginx-rtmp-module ( https://github.com/arut/nginx-rtmp-module )

wujianjun@wujianjun-work ~ $ sudo apt-get install build-essential
wujianjun@wujianjun-work ~ $ wget wget http://nginx.org/download/nginx-1.13.6.tar.gz
wujianjun@wujianjun-work ~/nginx-1.13.6 $ wget https://github.com/arut/nginx-rtmp-module/archive/v1.1.11.tar.gz
wujianjun@wujianjun-work ~/nginx-1.13.6 $ tar -xvf v1.1.11.tar.gz
wujianjun@wujianjun-work ~/nginx-1.13.6 $ wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.38/pcre-8.38.tar.gz
wujianjun@wujianjun-work ~/nginx-1.13.6 $ tar -xvf pcre-8.38.tar.gz
wujianjun@wujianjun-work ~/nginx-1.13.6 $ ls -all
总用量 748
drwxr-xr-x 9 wujianjun wujianjun 4096 10月 15 11:39 .
drwxr-xr-x 63 wujianjun wujianjun 4096 10月 15 11:33 ..
drwxr-xr-x 6 wujianjun wujianjun 4096 10月 15 11:33 auto
-rw-r--r-- 1 wujianjun wujianjun 282456 10月 10 23:22 CHANGES
-rw-r--r-- 1 wujianjun wujianjun 430416 10月 10 23:22 CHANGES.ru
drwxr-xr-x 2 wujianjun wujianjun 4096 10月 15 11:33 conf
-rwxr-xr-x 1 wujianjun wujianjun 2502 10月 10 23:22 configure
drwxr-xr-x 4 wujianjun wujianjun 4096 10月 15 11:33 contrib
drwxr-xr-x 2 wujianjun wujianjun 4096 10月 15 11:33 html
-rw-r--r-- 1 wujianjun wujianjun 1397 10月 10 23:22 LICENSE
drwxr-xr-x 2 wujianjun wujianjun 4096 10月 15 11:33 man
drwxrwxr-x 6 wujianjun wujianjun 4096 2月 13 2017 nginx-rtmp-module-1.1.11
drwxr-xr-x 7 wujianjun wujianjun 4096 11月 23 2015 pcre-8.38
-rw-r--r-- 1 wujianjun wujianjun  49 10月 10 23:22 README
drwxr-xr-x 9 wujianjun wujianjun 4096 10月 15 11:33 src
wujianjun@wujianjun-work ~/nginx-1.13.6 $ ./configure --with-pcre=pcre-8.38 --add-module=nginx-rtmp-module-1.1.11
wujianjun@wujianjun-work ~/nginx-1.13.6 $ make && sudo make install
wujianjun@wujianjun-work ~/nginx-1.13.6 $ ls -all /usr/local/nginx/
总用量 24
drwxr-xr-x 6 root root 4096 10月 15 16:11 .
drwxr-xr-x 11 root root 4096 10月 15 16:11 ..
drwxr-xr-x 2 root root 4096 10月 15 16:11 conf
drwxr-xr-x 2 root root 4096 10月 15 16:11 html
drwxr-xr-x 2 root root 4096 10月 15 16:11 logs
drwxr-xr-x 2 root root 4096 10月 15 16:11 sbin

增加rtmp协议配置

wujianjun@wujianjun-work ~/nginx-1.13.6 $ sudo vi /usr/local/nginx/conf/nginx.conf

在nginx.conf文件末尾增加以下rtmp协议的配置

rtmp {
 server {
  listen 1935;
  chunk_size 4096;

  application live {
   live on;
   record off;
  }
 }
}

启动&测试

启动nginx

wujianjun@wujianjun-work ~/nginx-1.13.6 $ sudo /usr/local/nginx/sbin/nginx

启动OBS

打开刚安装的OBS软件,在来源处配置图像的推送来源(我这里选择窗口捕获),点击右下角”设置”,进行如下图配置流推送地址

未分类

配置完成后,点击”开始推流”

启动支持网络流播放的视频播放器(演示使用vlc播放器)

配置网络流播放的地址,如下图:

未分类

当点击”播放”后,稍等几秒,即可看到播放器显示了obs捕获的图像了。

未分类

由于视频流需要通过网络进行传输,所以直播图像会有几秒的延迟。

http访问直播视频

1、更改nginx.conf中配置,增加hls配置(hls是在流媒体服务器中用来存放流媒体的文件夹),再次hls所在目录设置为http协议访问目录即可,更改后的配置如下:

rtmp {
 server {
  listen 1935;
  chunk_size 4096;

  application live {
   live on;
   hls on;
   hls_path /usr/share/nginx/html/hls;
   hls_fragment 5s;
  }
 }
}

http {
 server {
 listen 80;
 .....
 location / {
   #root html;
   root /usr/share/nginx/html;
   index index.html index.htm;
 }
 .....
 }
}

注意:hls所在目录nginx的用户必须有写入权限。

2、obs软件配置录制流名称

在配置obs推送流URL的下方有一个设置”流名称”的地方,这里可以随意填写一个名称(我这里示例填入”test”)

3、重启一下nginx与obs软件,我们即可在手机浏览器中输入 http://ip/hls/test.m3u8 即可通过手机播放直播视频。(直播延迟有点大,后续出文章优化)

未分类

zabbix自定Nginx状态监控

监控效果

未分类

未分类

自定义监控脚本

#!/bin/bash
#author:51itinfo.com
## Active connections: 对后端发起的活动连接数
## Server accepts handled requests: accepts表示共处理了多少个连接,handled表示成功创建了 多少次握手(没有失败次数),requests表示总共处理了多少个请求
## Reading: Nginx 读取到客户端的 Header 信息数
## Writing: Nginx 返回给客户端的 Header 信息数
## Waiting: 开启 keep-alive 的情况下,这个值等于 active - ( reading + writing ), 意思是 Nginx 已经处理完成,正在等待下一次请求指令的驻留连接
## 在访问效率很高,请求很快被处理完毕的情况下,Waiting 数比较多是正常的。如果 reading + writing 数较多,则说明并发访问量很大,正在处理过程中

case $1 in
    active)
        curl -s http://127.0.0.1/nginx_status | awk '/Active/ {print $3}' ;;
    accepts)
        curl -s http://127.0.0.1/nginx_status | awk 'NR==3 {print $1}' ;;
    handled)
        curl -s http://127.0.0.1/nginx_status | awk 'NR==3 {print $2}' ;;
    requests)
        curl -s http://127.0.0.1/nginx_status | awk 'NR==3 {print $3}' ;;
    reading)
        curl -s http://127.0.0.1/nginx_status | awk '/Reading/ {print $2}' ;;
    writing)
        curl -s http://127.0.0.1/nginx_status | awk '/Writing/ {print $4}' ;;
    waiting)
        curl -s http://127.0.0.1/nginx_status | awk '/Waiting/ {print $6}' ;;
    *)
        echo "Usage: $0 { active | accepts | handled | requests | reading | writing | waiting }" ;;
esac

nginx 服务器重启命令,关闭

未分类

nginx -s reload  :修改配置后重新加载生效
nginx -s reopen  :重新打开日志文件
nginx -t -c /path/to/nginx.conf 测试nginx配置文件是否正确

关闭nginx:

nginx -s stop  :快速停止nginx
nginx -s quit  :完整有序的停止nginx

其他的停止nginx 方式:

ps -ef | grep nginx

kill -QUIT 主进程号 :从容停止Nginx kill -TERM 主进程号 :快速停止Nginx pkill -9 nginx :强制停止Nginx

启动nginx:

nginx -c /path/to/nginx.conf

平滑重启nginx:

kill -HUP 主进程号

Mac下Nginx端口被占用问题

配置PHP过程中看到nginx的日志文件大小达到800多MB,里面的日志内容多是:nginx: [emerg] bind() to 0.0.0.0:80 failed (48: Address already in use)等端口占用信息,不免好奇。

Mac默认的Apache已经stop,再无其他应用、程序占用80端口。事实上,netstat分析也显示没有其他进程占用,但结果就摆在眼前,仍在不停输出。通过搜索发现,可能是IPv6所致。于是带上–with-ipv6选项重新编译,并监听ipv6地址,设为ipv6only=on。重新reload后,转为报错:nginx: [emerg] bind() to [::]:80 failed (48: Address already in use)。看来,网上的解决方案无济于事。

逐渐尝试升级Nginx、换端口,问题依旧,只是提示信息改为8080、8081等。看来,问题并不出在ipv6等配置上。

升级过程中,偶然的发现,sudo launchctl unload org.nginx.plist后,似乎报错停止了。于是,恢复配置,reload后,进行了unload测试。果不其然,事实证实如此。问题完美解决。

nginx yii2 配置路径 500问题

困扰了一个上午的问题

nginx conf中将yii2项目的路径配置到 根目录不会出错。
但是 配置到 frontend/web下 时 访问 就会报错500 服务器内部错误

不死心的我 google了很久。。。。。。。

发现和php 的 open_basedir有关系

改了下。

未分类

更改 你要显示的路径

报错解决。

Nginx 反向代理实现 Kibana 登录认证功能

Kibana 5.5 版后,已不支持认证功能,也就是说,直接打开页面就能管理,想想都不安全,不过官方提供了 X-Pack 认证,但有时间限制。毕竟X-Pack是商业版。

下面我将操作如何使用Nginx反向代理实现kibana的认证功能。

先决条件:

《Centos 7 源码编译安装 Nginx》

https://www.renwole.com/archives/39

1. 安装 Apache Httpd 密码生成工具

$ yum install httpd-tools -y

2. 生成Kibana认证密码

$ mkdir -p /usr/local/nginx/conf/passwd
$ htpasswd -c -b /usr/local/nginx/conf/passwd/kibana.passwd Userrenwolecom GN5SKorJ
Adding password for user Userrenwolecom

3. 配置Nginx反向代理

在Nginx配置文件中添加如下内容(或新建配置文件包含):

$ vim /usr/local/nginx/conf/nginx.conf

server {
listen 10.28.204.65:5601;
auth_basic "Restricted Access";
auth_basic_user_file /usr/local/nginx/conf/passwd/kibana.passwd;
location / {
proxy_pass http://10.28.204.65:5601;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade; 
}
}

4. 配置Kibana

取消下面注释:

$ vim /usr/local/kibana/config/kibana.yml

server.host: "10.28.204.65"

5. 重启 Kibana 及 Nginx 服务使配置生效

$ systemctl restart kibana.service
$ systemctl restart nginx.service

接下来浏览器访问 http://103.28.204.65:5601/ 会提示验证弹窗,输入以上生成的用户密码登录即可。