nginx

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
+ using PCRE library: /mnt/application/pcre-8.32
+ OpenSSL library is not used
+ using builtin md5 code
+ sha1 library is not found
+ using zlib library: /mnt/application/zlib-1.2.8

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"
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"

从源码安装nginx

拷贝nginx 到sbin

分析access.log 访问量

access.log是记录了所有的nginx的访问链接,并且纪录了这些访问的结果。可以使用python中的正则表达式来对其进行解析。这里需要python的re模块

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import re
ip = r"?P<ip>[\d.]*"
date = r"?P<date>\d+"
month = r"?P<month>\w+"
year = r"?P<year>\d+"
log_time = r"?P<time>\S+"
method = r"?P<method>\S+"
request = r"?P<request>\S+"
status = r"?P<status>\d+"
bodyBytesSent = r"?P<bodyBytesSent>\d+"
refer = r"""?P<refer>
[^\"]*
"""
userAgent=r"""?P<userAgent>
.*
"""
p = re.compile(r"(%s)\ -\ -\ \[(%s)/(%s)/(%s)\:(%s)\ [\S]+\]\ \"(%s)?[\s]?(%s)?.*?\"\ (%s)\ (%s)\ \"(%s)\"\ \"(%s).*?\"" %( ip, date, month, year, log_time, method, request, status, bodyBytesSent, refer, userAgent ), re.VERBOSE)
m = re.findall(p, line)

分割access.log

安装方法1

以ubuntu 14.04为例,其中的codename是trusty
因此需要把下面的代码追加到

1
2


deb http://nginx.org/packages/ubuntu/ trusty nginx
deb-src http://nginx.org/packages/ubuntu/ trusty nginx

1
2

然后运行

sudo apt-get update
sudo apt-get install nginx

1
2
3
4
5
6

这个安装方式有问题的

### 安装方法2 ###

#### 安装pcre ####

cd /usr/local/src
sudo wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.37.tar.gz
sudo tar -zxvf pcre-8.37.tar.gz
cd pcre-8.34
sudo ./configure
sudo make
sudo make install

1
2

#### 安装zlib ####

cd /usr/local/src
sudo wget http://zlib.net/zlib-1.2.8.tar.gz
sudo tar -zxvf zlib-1.2.8.tar.gz
cd zlib-1.2.8/
sudo ./configure
sudo make
sudo make install

1
2

#### 安装ssl ####

cd /usr/local/src
sudo wget https://www.openssl.org/source/openssl-1.0.1t.tar.gz
sudo tar -zxvf openssl-1.0.1t.tar.gz

1
2

#### 安装 nginx ####

cd /usr/local/src
wget http://nginx.org/download/nginx-1.8.1.tar.gz
tar -zxvf nginx-1.8.1.tar.gz
cd nginx-1.8.1.tar.gz
sudo ./configure –sbin-path=/usr/local/nginx/nginx –conf-path=/usr/local/nginx/nginx.conf –pid-path=/usr/local/nginx/nginx.pid –with-http_ssl_module –with-pcre=/usr/local/src/pcre-8.37 –with-zlib=/usr/local/src/zlib-1.2.8 –with-openssl=/usr/local/src/openssl-1.0.1t
sudo make
sudo make install
`

分享到