Nginx 每一个配置文件详解;Nginx 每一条编译参数详解;Nginx 基本配置内容详解

一:Nginx 所有的配置文件

我所解释的每一个配置文件都是通过:[root@localhost ~]# rpm -ql nginx     命令查出来的
/etc/logrotate.d/nginx        日志轮转文件

/etc/nginx/nginx.conf         总配置文件

/etc/nginx/conf.d                子配置文件夹

/etc/nginx/conf.d/default.conf    默认的网站配置( /usr/share/nginx/html/ )文件

/etc/nginx/fastcgi_params      动态网站模块文件-python,php所需的相关变量

/etc/nginx/scgi_params       fastcgi映射关系

/etc/nginx/uwsgi_params  fastcgi映射关系,将 Nginx 中的变量翻译成 Python 中能够理解的变量

/etc/nginx/koi-utf        字符集,文件编码

/etc/nginx/win-utf   字符集,文件编码

/etc/nginx/koi-win   字符集,文件编码

/etc/nginx/mime.types    文件关联程序网站文件类型 和 相关处理程序

/etc/nginx/modules     模块文件夹。第三方模块

/etc/sysconfig/nginx    标注nginx的安装目录和主配置文件路径

/etc/sysconfig/nginx-debug  

/usr/lib/systemd/system/nginx-debug.service         nginx调试程序启动脚本

/usr/lib/systemd/system/nginx.service systemctl    服务脚本。

/usr/sbin/nginx    主程序

/usr/sbin/nginx-debug    nginx调式程序

/usr/share/doc/nginx-1.12.1   文档

/usr/share/doc/nginx-1.12.1/COPYRIGHT   文档

/usr/share/man/man8/nginx.8.gz     man手册

/usr/share/nginx         nginx安装目录

/usr/share/nginx/html      主页默认目录

/usr/share/nginx/html/50x.html      错误页面500 502 503 504的提示页面

/usr/share/nginx/html/index.html     nginx默认主页

/var/cache/nginx        默认缓存

/var/log/nginx          存放日志的文件夹

/usr/lib64/nginx                 nginx模块目录

二:Nginx 编译参数

以下nginx所有编译参数都是执行:nginx -V 2>&1 | sed 's/ /\n/g'          语句拿到的
configure arguments:            配置参数./configure --help查询帮助

--prefix=/etc/nginx                 安装路径

--sbin-path=/usr/sbin/nginx            程序文件,执行nginx就是执行的这个文件

--modules-path=/usr/lib64/nginx/modules         模块路径

--conf-path=/etc/nginx/nginx.conf                 主配置文件

--error-log-path=/var/log/nginx/error.log               错误日志所在位置

--http-log-path=/var/log/nginx/access.log            网站访问日志的位置上

--pid-path=/var/run/nginx.pid                            程序ID,进程标识符所在位置

--lock-path=/var/run/nginx.lock                        锁路径,防止重复启动nginx

--http-client-body-temp-path=/var/cache/nginx/client_temp               客户机缓存

--http-proxy-temp-path=/var/cache/nginx/proxy_temp                    代理缓存

--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp              PHP缓存

--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp                           Python缓存

--http-scgi-temp-path=/var/cache/nginx/scgi_temp 

--with-compat                                     启用动态模块兼容性

--user=nginx                                      用户

--group=nginx                                     用户组

--with-file-aio                                使用nginx的aio特性会大大提高性能,aio的优点就是能够同时提交多个io请求给内核,然后直接由内核的io调度算法去处理这些请求(directio),这样的话,内核就有可能执行一些合并,节约了读取文件的处理时间,也就是一部非阻塞。

--with-threads                                   多线程模块

--with-http_addition_module            响应之前或者之后追加文本内容,比如想在站点底部追加一个js广告或者新增的css样式

--with-http_auth_request_module                         认证模块

--with-http_dav_module                         增加上传PUT,DELETE,MKCOL:创建集合,COPY和MOVE方法)默认情况下为关闭

 --with-http_flv_module                             NGINX 添加MP4、FLV视频支持模块

--with-http_gunzip_module                      压缩模块

--with-http_gzip_static_module 

--with-http_mp4_module                        多媒体模块

--with-http_random_index_module             nginx显示随机首页模块

--with-http_realip_module                     nginx获取真实ip模块

--with-http_secure_link_module             nginx安全下载模块

--with-http_slice_module                        nginx中文文档

--with-http_ssl_module                           安全模块

--with-http_stub_status_module                 访问状态

--with-http_sub_module                          nginx替换网页访问内容

--with-http_v2_module

--with-mail                                     邮件客户端

--with-mail_ssl_module 

--with-stream                              负载均衡模块。nginx从1.9.0开始,新增加了一个stream模块,用来实现四层协议的转发、代理或者负载均衡等。

--with-stream_realip_module 

--with-stream_ssl_module

--with-stream_ssl_preread_module 

--with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --
param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' 
--with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'                         这三行都是CPU优化参数

三:Nginx 基本配置内容详解

首先,我们先观察一下主配置文件中内容   vim /etc/nginx/nginx.conf

首先我先总体性的讲一下主配置文件中的五大模块

     1、全局/核心块:配置影响nginx全局的指令。一般有运行nginx服务器的用户组,nginx进程pid存放路径,日志存放路径,配置文件引入,允许生成worker process数等。

    2、events块:配置影响nginx服务器或与用户的网络连接。有每个进程的最大连接数,选取哪种事件驱动模型处理连接请求,是否允许同时接受多个网路连接,开启多个网络连接序列化等。

    3、http块:可以嵌套多个server,配置代理,缓存,日志定义等绝大多数功能和第三方模块的配置。如文件引入,mime-type定义,日志自定义,是否使用sendfile传输文件,连接超时时间,单连接请求数等。

    4、server块:配置虚拟主机的相关参数,一个http中可以有多个server。

    5、location块:配置请求的路由,以及各种页面的处理情况。 

user nginx;                   运行nginx程序的独立账号

worker_processes 1;          启动的worker进程数量(CPU数量一致或auto)

error_log /var/log/nginx/error.log warn;             错误日志存放位置

pid /var/run/nginx.pid;            nginx PID存放位置

events {                           事件,从这个{到下个}都是事件块的内容

use epoll;                        事件驱动模型epoll【默认】;事件驱动模型分类select|poll|kqueue|epoll|resig|/dev/poll|eventport

worker_connections 10240;                   每个worker进程允许处理的最大连接数,例如后面的这个10240

}                                     

http {                            http块

include /etc/nginx/mime.types;                   文档和程序的关联记录

default_type application/octet-stream;                 字节流处理方式

log_format main '$remote_addr - $remote_user [$time_local] "$request" '            

'$status $body_bytes_sent "$http_referer" '

'"$http_user_agent" "$http_x_forwarded_for"';             日志格式,讲日志回来看

access_log /var/log/nginx/access.log main;                         主访问日志文件

sendfile on;                                   优化参数,高效传输文件的模式开启这个参数后可以让数据不用经过用户buffer。

#tcp_nopush on;                            优化参数,tcp_nopush = on 会设置调用tcp_cork方法,数据包不会马上传送出去,等到数据包最大时,一次性的传输出去,这样有助于解决网络堵塞。

keepalive_timeout 65;                        优化参数 ,长连接

#gzip on;                          压缩参数

include /etc/nginx/conf.d/*.conf;                  包含子配置文件夹

观察默认虚拟主机配置模块

vim /etc/nginx/conf.d/default.conf 

server {             默认网站配置文件

listen 80;          监听端口、

server_name localhost;                 FQDN

#charset koi8-r;                           网页字符类型

#access_log /var/log/nginx/host.access.log main;                访问日志存放路径

location / {

root /usr/share/nginx/html;           主目录

index index.html index.htm;           默认主页名

}

#error_page 404 /404.html;                   错误页面

# redirect server error pages to the static page /50x.html 

error_page 500 502 503 504 /50x.html;                  错误页面

location = /50x.html {                                           错误页面

root /usr/share/nginx/html;                              错误页面主目录

}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80                     代理设置

#location ~ \.php$ {

# proxy_pass http://127.0.0.1;

#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000                动态网站设置

#location ~ \.php$ {

# root html;

# fastcgi_pass 127.0.0.1:9000;

# fastcgi_index index.php;

# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;

# include fastcgi_params;

#}# deny access to .htaccess files, if Apache's document root          访问控制部分

# concurs with nginx's one

#location ~ /\.ht { 

# deny all;

#}

}

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值