1.配置文件结构

Nginx的配置文件是一个纯文本文件,它一般位于Nginx安装目录的conf目录下,整个配置文件是以block的形式组织的。每个block一般以一组大括号“{}”来表示,block可以分为以下几个层次:main层、events层、http层等,而在http层中又包含有server层,即server block,server block 中又可分为location层,并且一个server block中可以包含多个location block。

如下:

#main层

……

events{

……

}

http{

……

server{

……

location{

……

}

}

}

mian层:全局配置,影响其他所有设置。

server层:主机配置,主要用于指定主机和端口。

upstream:负载均衡服务器设置,主要用于负载均衡,设置一系列后端服务器。

location:URL匹配特定位置的设置,用于匹配网页设置。

四者之间的关系:server继承main,location继承server,upstream既不会继承其他设置也不会被继承。

#user  nobody;                         #指定nginx worker 进程使用的用户及用户组
worker_processes  1;                    #表示每个worker进程所能建立的最大连接数,一个nginx能建立的最大连接数,应该是worker_connections * worker_processes;这里说的是最大连接数,对于HTTP请求本地资源来说,能够支持的最大并发数量是worker_connections * worker_processes,而如果是HTTP作为反向代理来说,最大并发数量应该是worker_connections * worker_processes/2。因为作为反向代理服务器,每个并发会建立与客户端的连接和与后端服务的连接,会占用两个连接。
#error_log  logs/error.log;            #定义错误日志,以及记录的等级(如:notice,info)
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
#pid        logs/nginx.pid;            #定义nginx进程位置
events {worker_connections  1024;        #定义允许连接数use epoll;                        #设置网络IO模型为epoll
}
http {include       mime.types;        #设定mime类型,类型由mime.type文件定义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 logs/access.log  main;        #定义访问日志sendfile        on;           #指令指定nginx是否调用sendfile函数(zero copy 方式)来输出文件,对于普通应用#tcp_nopush     on;#keepalive_timeout  0;keepalive_timeout  65;        #连接超时时间#gzip on;           #是否开启gzip压缩#设定负载均衡的服务器列表upstream mysvr {#weigth参数表示权值,权值越高被分配到的几率越大#本机上的Squid开启3128端口server 192.168.8.1:3128 weight=5;server 192.168.8.2:80  weight=1;server 192.168.8.3:80  weight=6;}server {listen       80;        #定义监听端口server_name  localhost;        #定义域名#charset koi8-r;#access_log  logs/host.access.log  main;        #定义本虚拟主机的访问日志#默认请求location / {root   html;        #定义服务器的默认网站根目录位置index  index.html index.htm;        #定义首页索引文件名称}#error_page  404              /404.html;       # redirect server error pages to thestatic page /50x.html#error_page   500 502 503 504  /50x.html;        #定义错误页面location = /50x.html {root   html;}# proxy the PHP scripts to Apachelistening on 127.0.0.1:80##location ~ \.php$ {#   proxy_pass   http://127.0.0.1;#}# pass the PHP scripts to FastCGIserver listening on 127.0.0.1:9000##PHP脚本请求全部转发到FastCGI处理,使用FastCGI默认设置#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, ifApache's document root# concurs with nginx's one##location ~ /\.ht {#   deny  all;#}}# another virtual host using mix of IP-,name-, and port-based configuration##server {#   listen       8000;#   listen       somename:8080;#   server_name  somename  alias another.alias;#   location / {#       root   html;#       index  index.html index.htm;#   }#}# HTTPS server##server {#   listen       443;#   server_name  localhost;#   ssl                  on;#   ssl_certificate      cert.pem;#   ssl_certificate_key  cert.key;#   ssl_session_timeout  5m;#   ssl_protocols  SSLv2 SSLv3 TLSv1;#   ssl_ciphers  HIGH:!aNULL:!MD5;#   ssl_prefer_server_ciphers   on;#   location / {#       root   html;#       index  index.html index.htm;#   }#}
}

转载于:https://blog.51cto.com/xiguanmin/1357882

nginx 配置文件相关推荐

  1. Nginx配置文件nginx.conf中文详解(转)

    ######Nginx配置文件nginx.conf中文详解######定义Nginx运行的用户和用户组 user www www;#nginx进程数,建议设置为等于CPU总核心数. worker_pr ...

  2. [Nginx优化]分享nginx配置文件及优化说明

    1.系统及内核方面     根据服务器用途,建议系统最小化安装或针对web服务器进行系统内核重新编译:在内核参数的一些优化,如下: # Add net.ipv4.tcp_max_syn_backlog ...

  3. Linux下查找nginx配置文件路径

    1.查看nginx进程 ps -aux | grep nginx 2.测试Nginx配置文件 /usr/local/nginx/sbin/nginx -t

  4. Linux下查找Nginx配置文件位置

    1.查看Nginx进程 命令: ps -aux | grep nginx 圈出的就是Nginx的二进制文件 2.测试Nginx配置文件 /usr/sbin/nginx -t 可以看到nginx配置文件 ...

  5. python修改nginx配置文件_zookeeper 动态管理nginx配置

    假设我们有一个场景,所有服务器共享同一份配置文件,我们肯定不可能单独手动维护每台服务器,这时可以利用zookeeper的配置管理功能. 环境:python + nginx + zookeeper 目的 ...

  6. nginx配置文件及工作原理详解

    nginx配置文件及工作原理详解 1 nginx配置文件的结构 2 nginx工作原理 1 nginx配置文件的结构 1)以下是nginx配置文件默认的主要内容: #user nobody; #配置用 ...

  7. Nginx配置文件粗解

    为什么80%的码农都做不了架构师?>>>    上一篇搭建了nginx+php基本环境,这一篇专门来学习nginx配置文件,以及怎样让nginx支持php,nginx的配置文件结构类 ...

  8. 搭建nginx服务、nginx的升级安装、Nginx配置文件的解析、web页面用户认证

    一,Nginx安装 1.安装nginx #  yum -y install gcc pcre-devel openssl-devel                              //安装 ...

  9. nginx配置文件【转载】

    转自 nginx的配置和使用 - chabale的专栏 - 博客频道 - CSDN.NET http://blog.csdn.net/chabale/article/details/8954226 # ...

  10. Nginx配置文件nginx.conf的文件结构

    我们知道Nginx的核心配置文件默认是放在/usr/local/nginx/conf/nginx.conf,这一节,我们就来学习下nginx.conf的内容和基本配置方法. 读取Nginx自带的Ngi ...

最新文章

  1. sqlalchemy.exc.InternalError: (pymysql.err.InternalError) Packet sequence number wrong - got 40 expe
  2. 小白看Word2Vec的正确打开姿势|全部理解和应用
  3. java hashmap 输出_JAVA如何把HashMap内容输出到文本文件
  4. Android 高级Drawable资源---复合Drawable----级别列表Drawabled
  5. 产品经验谈:推荐系统实战案例-如何寻找有用的用户行为?
  6. python indices_python numpy triu_indices函数
  7. 天价部队到老家赶来java作文_天价与廉价作文800字
  8. Mysql--Auto_increment详解
  9. Python基本语法
  10. Linux Shell中的简单命令组合使用
  11. SVG霍比特人电影标题样式
  12. console接口是干嘛的(console接口是干嘛的电信室外光猫)
  13. PHP合并两张(多张)图片
  14. m基于LS+变步长LMS的Volterra级数数字预失真DPD系统matlab仿真
  15. 手机拍证件照有什么诀窍
  16. 微信屏蔽抖音?扎克伯格登报发表道歉信
  17. 设备管理的方法与思路-设备管理软件系统-璞华大数据
  18. 【Paraview教程】第一章安装与基础介绍
  19. 大数据分析案例-基于决策树算法构建金融反欺诈分类模型
  20. 修改登录ftp服务器时用的密码,ftp服务器登录密码修改

热门文章

  1. 拼多多高速冲刺8亿用户新时代 黄峥卸任董事长 探索行业未来十年发展
  2. 余承东:国内用华为P40 Pro+就能拍照测体温,还很精准
  3. svn 413 Request Entity Too Large 错误
  4. 【290】Python 函数
  5. playbook核心元素之 模板template 介绍(7)
  6. 设计原则——依赖倒置
  7. java对象深入理解
  8. WebX5 button tabs的bind-text属性设置
  9. Android webkit 事件传递流程
  10. 就是这么简单(续)!使用 RestAssuredMockMvc 测试 Spring MVC Controllers(转)