Nginx include和Nginx指令的使用
Nginx include和Nginx指令的使用
1、nginx include
主配置文件nginx.conf中指定包含其他扩展配置文件,从而简化nginx主配置文件,实现多个站点功能
[root@Web01 conf]# cat nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
include /application/nginx/conf/extra/*.conf;
}
在/application/nginx/conf/extra下创建多个配置文件
批量生成扩展主页配置文件进行测试,编写脚本
mkdir -p /application/nginx/conf/extra #创建存放每个站点文件的目录
生成的扩展页面在/application/nginx/conf/extra目录下
[root@Web01 conf]# mkdir -p /service/scripts
[root@Web01 conf]# vim /service/scripts/auto.sh
[root@Web01 conf]# cat /service/scripts/auto.sh
#!/bin/bash
for i in `seq 11 20`;
do
echo "server {
listen 80;
server_name ${i}.test.com;
location / {
root html/$i;
index index.html index.htm;
}
}" >>/application/nginx/conf/extra/${i}.conf
mkdir -p /application/nginx/html/$i
echo "$i test">>/application/nginx/html/$i/index.html
done
[root@Web01 conf]#
添加浏览器所在系统本地host解析
[root@Web01 conf]# seq -f %g.test.com 11 20|xargs #生成hosts解析内容
11.test.com 12.test.com 13.test.com 14.test.com 15.test.com 16.test.com 17.test.com 18.test.com 19.test.com 20.test.com
[root@Web01 conf]#
编辑Windows系统的host解析

浏览器访问,不同域名对应不同页面
2、nginx指令使用
2.1. upstream
声明一组可以被proxy_pass和fastcgi_pass引用的服务器;这些服务器可以使用不同的端口,并且也可以使用Unix Socket;也可以为服务器指定不同的权重。如:
upstream web_pool {
server coolinuz.9966.org weight=5;
server 172.23.136.148:8080 max_fails=3 fail_timeout=30s;
server unix:/tmp/backend3;
}
2.2. server
语法:server name [parameters]
其中的name可以是FQDN,主机地址,端口或unix套接字;如果FQDN解析的结果为多个地址,则每个地址都会被用到。
2.3. proxy_pass
语法:proxy_pass URL;
该指令用于指定代理服务器的地址和URL将被映射为的URL或地址和端口。即用来指定后端服务器的地址或URL[端口]。
2.4. proxy_set_header
语法:proxy_set_header header value;
该指令允许重新定义和添加一些将被转移到被代理服务器的请求头部信息。
例如:
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
注意:$proxy_add_x_forwarded_for包含客户端请求头中的"X-Forwarded-For",与$remote_addr用逗号分开,如果没有"X-Forwarded-For" 请求头,则$proxy_add_x_forwarded_for等于$remote_addr
2.5. proxy_read_timeout
语法:proxy_read_timeout time;
这个指令设置Nginx与后端服务器建立连接后。等待后端服务器的响应时间
2.6. proxy_send_timeout
语法:roxy_send_timeout time;
该指令指定请求转移到后端服务器的超时时间。整个传输的要求时间不超过超时时间,但只有两次写操作之间。如果在此时间之后的后端服务器将不采取新的数据,然后nginx将关闭连接。
2.7. proxy_connect_timeout
语法:proxy_connect_timeout time;
该指令用来设置分配到后端服务器的连接超时时间。
2.8. proxy_buffers
语法: proxy_buffers the_number is_size;
该指令设置缓冲区的数目和大小,缺省情况下,一个缓冲区的大小和页面大小相同。
2.9. proxy_buffer_size
语法:proxy_buffer_size buffer_size;
代理缓冲区,该指令用于保存用用户的头部信息。
2.10. proxy_busy_buffers_size
语法:proxy_busy_buffers_size size;
用于当系统负载较大,缓冲区不够用时,可以申请更大的proxy_buffers
2.11. proxy_temp_file_write_size
语法:proxy_temp_file_write_size size;
用于指定缓存临时文件的大小
Nginx include和Nginx指令的使用的更多相关文章
- 2.4 Nginx服务器基础配置指令
2.4.1 nginx.conf文件的结构 2.4.2配置运行Nginx服务器用户(组) 2.4.3配置允许生成的worker process数 2.4.4 配置Nginx进程PID存放路径 2.4. ...
- CentOS + Nginx 的常用操作指令总结
CentOS + Nginx 的常用操作指令总结 一. 关于CentOS 查看 yum 源是否存在 yum list | grep nginx 如果不存在 或者 不是自己想要的版本 可以自己设置Ngi ...
- Nginx RTMP 模块 nginx-rtmp-module 指令详解
译序:截至 Jul 8th,2013 官方公布的最新 Nginx RTMP 模块 nginx-rtmp-module 指令详解.指令Corertmp语法:rtmp { ... }上下文:根描述:保存所 ...
- Nginx user_agent、if指令及全局变量
Nginx user_agent.if指令及全局变量 1.User_agent User Agent中文名为用户代理,简称 UA,它是一个特殊字符串头,使得服务器能够识别客户使用的操作系统及版本.CP ...
- nginx location中root指令和alias指令的区别
nginx location中root指令和alias指令 功能:将url映射为文件路径,以返回静态文件内容 差别:root会将完整的url映射进文件路径中 alias只会将location后的url ...
- Java高级架构师(一)第33节:Nginx常用核心模块指令
error_log:错误日志级别 http://www.nginx.cn/doc/ Nginx中文文档 # 并发总数是 worker_processes 和 worker_connections 的 ...
- 【夯实Nginx基础】Nginx工作原理和优化、漏洞
本文地址 原文地址 本文提纲: 1. Nginx的模块与工作原理 2. Nginx的进程模型 3 . NginxFastCGI运行原理 3.1 什么是 FastCGI ...
- nginx入门篇----nginx服务器基础配置
1.nginx.conf文件结构... #全局块 events{ ... } http #http块{ ...
- Nginx配置文件(nginx.conf)配置详解(2)
Nginx的配置文件nginx.conf配置详解如下: user nginx nginx ; Nginx用户及组:用户 组.window下不指定 worker_processes 8; 工作进程:数目 ...
随机推荐
- 【HDU 2594 Simpsons' Hidden Talents】
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...
- 《c程序设计语言》读书笔记-5.5-指针实现strncpy,strncat,strncmp
#include <stdio.h> #include <math.h> #include <stdlib.h> #include <string.h> ...
- 物理和虚拟兼容性RDM的区别
Difference between Physical compatibility RDMs and Virtual compatibility RDMs (2009226) Purpose This ...
- 今天写页面,将.net也使用了语义法规来判断。做法来源是.net ado.net的类型判断 Infertype。一样的原理
做了一个封装,使页面更容易维护一些.主要是两个方法,如下所示: private void BindModule(Action<Repeater, string> bindSingRpt) ...
- [LeetCode] Sqrt(x) 二分搜索
Implement int sqrt(int x). Compute and return the square root of x. Hide Tags Math Binary Search ...
- cookie登录
#coding:utf-8 import tornado.httpserver import tornado.ioloop import tornado.options import tornado. ...
- POCO库中文编程参考指南(5)Poco::Net::SocketAddress
1 枚举 最大地址长度,这个与Poco::Net::IPAddress中的定义可以类比,不过这里指的是`struct sockaddr_in6 enum { MAX_ADDRESS_LENGTH = ...
- ubuntu下安装 gSOAP 用于C/C++开发web service服务端与客户端
昨天在ubuntu下进行安装gSOAP,费了很多时间,没成功,今天又来找了大量教程资料,终于一次成功,这里写下自己的安装步骤和方法,供大家参考. 首先下载gsoap,我下载的是gsoap-2.8.1. ...
- java如何增加数组长度
遇到一个面试题:在不使用list的add方法的情况下,动态的添加元素(大概是这个样子): ArrayList是基于数组实现的,是一个动态数组,其容量能自动增长,需学习arraylist的相关知识(ht ...
- Hbase delete遇到的常见异常: Exception in thread "main" java.lang.UnsupportedOperationException
hbase 执行批量删除时出现错误: Exception in thread "main" java.lang.UnsupportedOperationException at j ...