1.利用全局变量$args。
下面的代码是在调用URL中参数s的值
例如:www.google.com?id=10&s=020&wan=009
这里就是直接取得s的值020.
- server {
- listen 81;
- server_name 127.0.0.1;
- #过滤参数
- location / {
- set $ss $arg_s;#如果要取得参数wan的值就应该写成 $arg_wan
- if ($ss = 020){
- return www.baidu.com;
- }
- if ($ss = 030){
- return www.baidu.com;
- }
- if ($ss = 050){
- return www.baidu.com;
- }
- return www.baidu.com;
- }
- }
2.windows 常用命令。
nginx.exe -s stop
start nginx.exe -c conf/default.conf
测试配置文件
nginx.exe -t -c conf/default.conf
nginx -V
nginx.exe -s reopen
nginx.exe -s quit
nginx.exe -s stop
3.nginx自动列目录功能
前提:目录下没有index.html这一类文件。这个功能可以当做一个文件服务器。
- location / {
- root C:\mysina ;
- autoindex_exact_size on; #设定索引时文件大小的单位
- autoindex_localtime on; #开启以本地时间来显示文件时间的功能,默认为关
- autoindex on;
4.ip_hash指令
默认值:none
使用环境 upstream
每个请求按访问ip的hash结果分配,这样每个访客固定访问一个后端服务器,可以解决session的问题。
5.Server 指令
Weight=2 权重
Max-fails=1 请求失败次数(404错误除外),默认1,取消时为0。
Fail_timeOut=30s 失败后,暂停的时间。默认为10s
Backup 在非backup服务器全部当机后才会启用。全部设置为服务器无法访问。
- upstream wan{
- ip_hash;
- server 127.0.0.1:81 max_fails=3 fial_timeout=30s;
- server 127.0.0.1:82 ;
- server 127.0.0.1:83 ;
- server 127.0.0.1:84 ;
- server 127.0.0.1:85 ;
- }
6.location中的匹配优先级
= 优先
~ 第二(同样的话按顺序)
/
优先匹配字符串,----正则表达式。(按写的顺序)
7.nginx 与tomcat的配置。
在配置文件中,html、图片、js、css、flash等由nginx来处理可得到更快的速度。
.jsp .do 有nginx反向代理给tomcat。配置网上很多。