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服务
|
|
使用ps命令也可以看到所有nginx进程,也可以验证nginx是否正常运行:
|
|
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
当然你访问多次,这个次数是会增加的。