文章目录
注意
如果用windows下面的浏览器测试nginx
name就需要配置windows下面的hosts文件
C:\Windows\System32\drivers\etc\hosts
一.nginx 第三方模块(必须重新编译安装)
注意版本要求:用nginx-14版本做实验
第三方模块是对nginx 的功能扩展,第三方模块需要在编译安装nginx 的时候
使用参数--add-module=PATH指定路径添加,有的模块是由公司的开发人员针对业务需求定制开发的,有的模块是开源爱好者开发好之后上传到github进行开源的模块,nginx支持第三方模块,需要重新编译源码才能支持
开源的echo模块,实现输出变量等信息(用于调试)
https://github.com/openresty/echo-nginx-module
示例:
#git是一款克隆工具,在互联网上的内容给下载下来
yum install git –y
# 这个目录下面可以存放一些源码包
cd /usr/local/src
git clone https://github.com/openresty/echo-nginx-module.git
cd nginx-1.16.0/
useradd –r –s /sbin/nologin nginx
yum install gcc pcre-devel openssl-devel zlib-devel perl-ExtUtils-Embed
# ./configure \
--prefix=/apps/nginx \
--user=nginx --group=nginx \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-http_perl_module \
--with-pcre \
--with-stream \
--with-stream_ssl_module \
--with-stream_realip_module \
--add-module=/usr/local/src/echo-nginx-module
#重要是最后一步---指定echo 模块路径
# make && make install
vim /apps/nginx/conf/conf.d/pc.conf
server {
location /test {
#不需要创建test,
index index.html;
#将他识别成默认的文本,而不是 下载
default_type text/html;
echo "hello world,main-->";
echo_reset_timer;
echo_location /sub1;
echo_location /sub2;
echo "took $echo_timer_elapsed sec for total.";
}
location /sub1 {
echo_sleep 1;
echo sub1;
}
location /sub2 {
echo_sleep 1;
echo sub2;
}

本文详细介绍了Nginx的配置,包括第三方模块的添加与使用,如echo模块;讲解了如何自定义日志格式并转换为JSON,以及open_log_file_cache的使用;讨论了如何处理favicon.ico请求避免404日志;此外,还阐述了autoindex模块实现文件下载服务和gzip模块的压缩配置。
最低0.47元/天 解锁文章
972

被折叠的 条评论
为什么被折叠?



