「三」配置语法、配置文件高亮
源码安装conf文件高亮
v1.18.0
v1.14.2
vim高亮脚本:sudo cp -r contrib/vim/* /usr/share/vim/vimfiles/
http配置的指令块
- http
- upstream
- server
- location
配置语法
- 配置文件由指令与指令快构成
- 每条指定以;结尾,指令与参数之间以空格符号分割
- 指令快以{}大括号将多条指令组织在一期
- include语句允许组合多个配置文件以提升可维护性
- 使用#符号添加注释,提高可读性
- 使用$符号使用变量
- 部分指定的擦数支持正则表达
worker_processes 1; #error_log logs/error.log; #pid logs/nginx.pid; events { worker_connections 1024; } #http:指令块 #include mime.types;:指令 http { #指令名 参数 include 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 logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; server { listen 80; server_name localhost; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } } 2,1 Top
upstream模块:可以实现负载均衡
upstream backend { server backend1.example.com weight=5; #执行realserver,可以赋权重 server backend2.example.com:8080; server unix:/tmp/backend3; server backup1.example.com:8080 backup; #backup表示该节点为热备节点,激活节点失效时启用 server backup2.example.com:8080 down; #下线服务器,可以在real服务器需要维护时配置 } server { listen 80; #listen、server_name这些正常配置 server_name www.test.com; location / { proxy_pass http://backend; ##反向代理执行定义的upstream名字 } }