nginx

目录
  1. nginx安装
  2. nginx模块

nginx安装

  • 下载链接:
    http://nginx.org/download/
    依赖库zlib, pcre

  • 编译及安装
    ./configure –prefix=/home/mycount/software/nginx-1.13.6 –with-pcre=/home/mycount/pcre-8.39 –with-zlib=/home/mycount/Downloads/zlib-1.2.11
    make install
    其中pcre-8.39及zlib-1.2.11 为pcre和zlib的源码目录(注意是源码目录)

  • 运行
    启动和停止nginx需要以root身份运行,或者使用sudo命令
    sbin/nginx #使用默认的配置文件conf/nginx.conf

  • 验证安装
    nginx的默认配置文件开启了localhost:80服务
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
[root@localhost ~]# curl -v -o /dev/null http://localhost/index.html
* About to connect() to localhost port 80 (#0)
* Trying 127.0.0.1... connected
* Connected to localhost (127.0.0.1) port 80 (#0)
> GET /index.html HTTP/1.1
> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.21 Basic ECC zlib/1.2.3 libidn/1.18 libssh2/1.4.2
> Host: localhost
> Accept: */*
>
< HTTP/1.1 403 Forbidden
< Server: nginx/1.13.6
< Date: Tue, 05 Dec 2017 14:35:32 GMT
< Content-Type: text/html
< Content-Length: 169
< Connection: keep-alive
<
{ [data not shown]
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
169 169 169 169 0 0 8154 0 --:--:-- --:--:-- --:--:-- 0* Connection #0 to host localhost left intact
* Closing connection #0

使用ps命令也可以看到所有nginx进程,也可以验证nginx是否正常运行:

1
2
3
4
ps aux |greo nignx
[root@localhost 13.6]# ps aux |grep nginx
root 109323 0.0 0.0 15768 624 ? Ss 22:34 0:00 nginx: master process /home/hy/software/nginx-1/13.6/sbin/nginx
nobody 109324 0.0 0.1 16212 1532 ? S 22:34 0:00 nginx: worker process

nginx模块

编译
[root@localhost nginx-1.13.6]# ./configure –prefix=/home/hy/software/nginx-1.13.6 –add-module=/home/hy/Documents/nginx-1.13.6/src/test/ –with-pcre=/home/hy/Downloads/pcre-8.39 –with-zlib=/home/hy/Downloads/zlib-1.2.11

编译时会提示:
configuring additional modules
adding module in /home/hy/Documents/nginx-1.13.6/src/test/

  • ngx_http_hello_module was configured
    creating objs/Makefile

如何支持C++文件?
需要简单了解下nginx的编译过程
1、直接修改Makefile文件
2、通过修改auto目录下的文件

使用
使用一个模块需要根据这个模块定义的配置指令来做。比如我们这个简单的hello handler module的使用就很简单。在我的测试服务器的配置文件里,就是在http里面的默认的server里面加入如下的配置:

location /test {
hello_string jizhao;
hello_counter on;
}
当我们访问这个地址的时候, lynx http://127.0.0.1/test的时候,就可以看到返回的结果。

jizhao Visited Times:1

当然你访问多次,这个次数是会增加的。

本站总访问量