nginx的学习笔记
2015-08-05 22:49
471 查看
相应的命令:
nginx.exe -s stop //停止nginx
nginx.exe -s reload //重新加载nginx
nginx.exe -s quit //退出nginx
---------------------------------------------------------------------------------------------------------------------- http://www.2cto.com/os/201212/176520.html(很好的配置)
----------------------------------------------------------------------------------------------------------------------
nginx和tomcat一起实现负载均衡
http://blog.sina.com.cn/s/blog_6caddb5001010q7i.html http://www.360doc.com/content/10/1215/14/58597_78364548.shtml
常用配置如下:
Nginx.conf代码
http {
server {
#1.侦听80端口
listen 80;
location / {
# 2. 默认主页目录在nginx安装目录的html子目录。
root html;
index index.html index.htm;
# 3. 没有索引页时,罗列文件和子目录
autoindex on;
autoindex_exact_size on;
autoindex_localtime on;
}
# 4.指定虚拟目录
location /tshirt {
alias D:\programs\Apache2\htdocs\tshirt;
index index.html index.htm;
}
}
# 5.虚拟主机www.emb.info配置
server {
listen 80;
server_name www.emb.info;
access_log emb.info/logs/access.log;
location / {
index index.html;
root emb.info/htdocs;
}
}
}
http {
server {
#1.侦听80端口
listen 80;
location / {
# 2. 默认主页目录在nginx安装目录的html子目录。
root html;
index index.html index.htm;
# 3. 没有索引页时,罗列文件和子目录
autoindex on;
autoindex_exact_size on;
autoindex_localtime on;
}
# 4.指定虚拟目录
location /tshirt {
alias D:\programs\Apache2\htdocs\tshirt;
index index.html index.htm;
}
}
# 5.虚拟主机www.emb.info配置
server {
listen 80;
server_name www.emb.info;
access_log emb.info/logs/access.log;
location / {
index index.html;
root emb.info/htdocs;
}
}
----------------------------------------------------------------------------------------------------------------------
http://os.51cto.com/art/201111/304451.htm
nginx的upstream目前支持4种方式的分配
1、轮询(默认)
每个请求按时间顺序逐一分配到不同的后端服务器,如果后端服务器down掉,能自动剔除。
2、weight
指定轮询几率,weight和访问比率成正比,用于后端服务器性能不均的情况。
2、ip_hash
每个请求按访问ip的hash结果分配,这样每个访客固定访问一个后端服务器,可以解决session的问题。
3、fair(第三方)
按后端服务器的响应时间来分配请求,响应时间短的优先分配。
4、url_hash(第三方)
按访问url的hash结果来分配请求,使每个url定向到同一个后端服务器,后端服务器为缓存时比较有效。
代理
只需要在nginx的配置文件中增加虚拟主机,然后加入
nginx.exe -s stop //停止nginx
nginx.exe -s reload //重新加载nginx
nginx.exe -s quit //退出nginx
---------------------------------------------------------------------------------------------------------------------- http://www.2cto.com/os/201212/176520.html(很好的配置)
----------------------------------------------------------------------------------------------------------------------
nginx和tomcat一起实现负载均衡
http://blog.sina.com.cn/s/blog_6caddb5001010q7i.html http://www.360doc.com/content/10/1215/14/58597_78364548.shtml
常用配置如下:
Nginx.conf代码
http {
server {
#1.侦听80端口
listen 80;
location / {
# 2. 默认主页目录在nginx安装目录的html子目录。
root html;
index index.html index.htm;
# 3. 没有索引页时,罗列文件和子目录
autoindex on;
autoindex_exact_size on;
autoindex_localtime on;
}
# 4.指定虚拟目录
location /tshirt {
alias D:\programs\Apache2\htdocs\tshirt;
index index.html index.htm;
}
}
# 5.虚拟主机www.emb.info配置
server {
listen 80;
server_name www.emb.info;
access_log emb.info/logs/access.log;
location / {
index index.html;
root emb.info/htdocs;
}
}
}
http {
server {
#1.侦听80端口
listen 80;
location / {
# 2. 默认主页目录在nginx安装目录的html子目录。
root html;
index index.html index.htm;
# 3. 没有索引页时,罗列文件和子目录
autoindex on;
autoindex_exact_size on;
autoindex_localtime on;
}
# 4.指定虚拟目录
location /tshirt {
alias D:\programs\Apache2\htdocs\tshirt;
index index.html index.htm;
}
}
# 5.虚拟主机www.emb.info配置
server {
listen 80;
server_name www.emb.info;
access_log emb.info/logs/access.log;
location / {
index index.html;
root emb.info/htdocs;
}
}
----------------------------------------------------------------------------------------------------------------------
http://os.51cto.com/art/201111/304451.htm
nginx的upstream目前支持4种方式的分配
1、轮询(默认)
每个请求按时间顺序逐一分配到不同的后端服务器,如果后端服务器down掉,能自动剔除。
2、weight
指定轮询几率,weight和访问比率成正比,用于后端服务器性能不均的情况。
2、ip_hash
每个请求按访问ip的hash结果分配,这样每个访客固定访问一个后端服务器,可以解决session的问题。
3、fair(第三方)
按后端服务器的响应时间来分配请求,响应时间短的优先分配。
4、url_hash(第三方)
按访问url的hash结果来分配请求,使每个url定向到同一个后端服务器,后端服务器为缓存时比较有效。
代理
只需要在nginx的配置文件中增加虚拟主机,然后加入
\proxy_pass http://localhost:8000;[/code]
负载均衡:
只需要在http中增加
upstream tgcluster {#定义负载均衡设备的Ip及设备状态
ip_hash;
server 127.0.0.1:9090 down;
server 127.0.0.1:8080 weight=2;
server 127.0.0.1:6060;
server 127.0.0.1:7070 backup;
}
在需要使用负载均衡的server中增加
proxy_pass http://tgcluster/;
每个设备的状态设置为:
1.down 表示单前的server暂时不参与负载
2.weight 默认为1.weight越大,负载的权重就越大。
3.max_fails :允许请求失败的次数默认为1.当超过最大次数时,返回proxy_next_upstream 模块定义的错误
4.fail_timeout:max_fails次失败后,暂停的时间。
5.backup: 其它所有的非backup机器down或者忙的时候,请求backup机器。所以这台机器压力会最轻。
nginx支持同时设置多组的负载均衡,用来给不用的server来使用。
client_body_in_file_only 设置为On 可以讲client post过来的数据记录到文件中用来做debug
client_body_temp_path 设置记录文件的目录 可以设置最多3层目录
location 对URL进行匹配.可以进行重定向或者进行新的代理 负载均衡
相关文章推荐
- nginx 进行外网地址屏蔽
- ElasticSearch:Nginx可以给ElasticSearch集群带来什么福利?
- 测试部署nginx
- Ubuntu 14.10下基于Nginx搭建mp4/flv流媒体服务器(可随意拖动)并支持RTMP/HLS协议(含转码工具)
- nginx upstream的几种配置方式
- 自己写了个nginx启动脚本,shell
- Nginx(2):工作机制
- PHP nginx 去掉伪静态的配置
- 使用Nginx+FFMPEG搭建HLS直播转码服务器
- Smooth Streaming Module for Nginx
- Nginx基础学习
- 在Nginx服务器中启用SSL的配置方法
- 详解Nginx服务器中的nginx.conf配置文件
- 在阿里云服务器(ECS)上从零开始搭建nginx服务器 推荐
- Nginx配置性能优化
- Apache与Nginx优缺点比较
- uwsgi部署到nginx出现invalid request block size: 4161 (max 4096)...skip问题
- 在Linux和Windows系统上安装Nginx服务器的教程
- nginx源码编辑带第三方模块lua
- Nginx的启动、停止、平滑启动、平滑升级