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; 工作进程:数目 ...
随机推荐
- 《c程序设计语言》读书笔记-递归实现快速排序算法
#include <stdio.h> void swap(int v[],int i,int j) { int temp; temp = v[i]; v[i] = v[j]; v[j] = ...
- SD卡给MCU升级
目 录1. 前言2. 初识BootLoader2.1 百度百科的BootLoader2.2 BootLoader的简单理解2.3 BootLoader的作用3. BootLoader预备知识3.1 复 ...
- java集合类深入分析之PriorityQueue(二)
PriorityQueue介绍 在平时的编程工作中似乎很少碰到PriorityQueue(优先队列) ,故很多人一开始看到优先队列的时候还会有点迷惑.优先队列本质上就是一个最小堆.前面一篇文章介绍了堆 ...
- .NET4中多线程并行方法Parallel.ForEach
原文发布时间为:2011-12-10 -- 来源于本人的百度文章 [由搬家工具导入] namespace ForEachDemo{ using System; using System.I ...
- QML与Qt C++ 交互机制探讨与总结(转)
原文转自 https://www.cnblogs.com/aoldman/p/4103510.html 介绍 QML和 C++对象可以通过,signals,slots和 属性修改进行交互.对于一个C+ ...
- 如何使用python查看视频的长度
import subprocess import re def get_length(filename): result = subprocess.Popen(["ffprobe" ...
- WCF 小程序案例以及序列化的使用
using System;using System.Collections.Generic;using System.Linq;using System.Runtime.Serialization;u ...
- 或许你不知道的10条SQL
一.一些常见的SQL实践 (1)负向条件查询不能使用索引 select * from order where status!=0 and stauts!=1 not in/not exists都不是好 ...
- mysql故障(主从复制sql线程不运行)
故障现象: 进入slave服务器,运行: mysql> show slave status\G ....... Relay_Log_File: localhost Relay_Log_Pos: ...
- Centos查看文件夹大小
查看当前目录下文件夹大小 du -h --max-depth=1 查看整体情况 df -h