首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 互联网 >

nginx研究(公司同人总结)

2012-07-27 
nginx研究(公司同事总结)windows 常用命令。??? nginx.exe -s stop? start nginx.exe -c conf/default.conf

nginx研究(公司同事总结)

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
------------------------------------
nginx自动列目录
前提:目录下没有index.html这一类文件
?location / {
??? ??? root C:\mysina ;
??????????? autoindex_exact_size? on;??? #设定索引时文件大小的单位
??????????? autoindex_localtime on;? #开启以本地时间来显示文件时间的功能,默认为关
??? autoindex on;
???? }
????
?-----------------------------------------------???



利用全局变量中的参数

server {
??? listen 81;
??? server_name? 127.0.0.1;
#过滤参数
??? location ~ /gg/go\.php{
??? ??? ??? ??? ??? ??? set $ss $arg_s;??? ???
??? ??? ??? ??? ??? ??? if ($ss = s020){
??? ??? ??? ??? ??? ??? return http://down2.uc.cn/down_wap.asp?f=chenhh@ttdt&id=27&ua=other&brand=other;
??? ??? ??? ??? ??? ??? }
??? ??? ??? ??? ??? ??? if ($ss = s030){
??? ??? ??? ??? ??? ??? return http://down2.uc.cn/down_wap.asp?f=chenhh@ttdt&id=28&ua=other&brand=other;
??? ??? ??? ??? ??? ??? }
??? ??? ??? ??? ??? ??? if ($ss = s050){
??? ??? ??? ??? ??? ??? return http://down2.uc.cn/down_wap.asp?f=chenhh@ttdt&id=50&ua=other&brand=other;
??? ??? ??? ??? ??? ??? }
??? ??? ??? ??? ??? ??? return http://down2.uc.cn/other.asp?f=chenhh@ttdt&url=wap.ttpod.com&title=%E5%A4%A9%E5%A4%A9%E8%BD%AF%E4%BB%B6%E9%83%A8%E8%90%BD;
??? ??? ??? ??? ??? }
??? }
???
------------------------


6.5节没看懂,双机高可用?

-------------------------------------------------
nginx的gzip压缩


一般情况下压缩后的html、css、js、php、jhtml等文件,大小能降至原来的25%,也就是说,原本一个100k的html,压缩后只剩下25k。这无疑能节省很多带宽,也能降低服务器的负载。
在nginx中配置gzip比较简单
具体可见http://wiki.codemongers.com/NginxChsHttpGzipModule
一般情况下只要在nginx.conf的http段中加入下面几行配置即可
?? gzip? on;
?? gzip_min_length? 1000;#压缩的最小字节数.默认是0,不管多大都压缩
?? gzip_buffers???? 4 8k;#设置获取几个单位的缓存用于gzip压缩结果数据流。
?? gzip_comp_level 6; #0-9 默认值为1,值越大压缩率越高,消耗的cpu资源越多,传输量减小。
?? gzip_types text/plain text/html text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
?? #匹配头文件
??
? ----------------------------------------------------

ip_hash指令
??? 默认值:none
??? 使用环境 upstream
??? 每个请求按访问ip的hash结果分配,这样每个访客固定访问一个后端服务器,可以解决session的问题。
???
???
---------------------------------------------------
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 ;
??? }


------------------------------------------------------
Location
?? location / {
?????????? root C:\mysina ;???? 文件路径。注意最后的\,这个有时候会出错。
?????????? index index3.html ;?? 默认首页的位置
???? }
http://127.0.0.1/index2.html

------------------------
expires(细看p38)
空值浏览器缓存,默认是关。
例子是对图片缓存30天。
location ~.*\.(gif|jpg|jpeg|swf)${
??? expires 30d;
}

-------------------------------------------------------

nginx 与tomcat的配置。
??? 在配置文件中,html、图片、js、css、flash等由nginx来处理可得到更快的速度。
??? .jsp .do 有nginx反向代理给tomcat。

worker_processes 2;
error_log C:\213.log;
#指定文件描述符数量
worker_rlimit_nofile 51200;
events {
??? #允许连接数。
??? worker_connections? 65535;
??? #linux下的模型????
??? #use epoll;
}
http {
??? #过滤头信息所需要的。例如:压缩中的gzip_type.
??? ??? include?????? mime.types;
??? ??? default_type? application/octet-stream;
??? charset utf-8;#设置字符集,如果项目中有多个字符集,不要设置,应该在html中Meta设置。
??? server_names_hash_bucket_size 128;
??? client_header_buffer_size 32k;
??? large_client_header_buffers 4 32k;
??? client_max_body_size 8m; #设置客户端能够上传的文件大小.
??? proxy_connext_timeout 600;??? #跟后端服务器连接超时时间
??? proxy_read_timeout 600;??? ??? #等待超时时间
??? proxy_send_timeout 600;??? ??? #后端回传必须传完的时间
??? proxy_buffer_size 16k;??? ??? #代理缓存区,保存用户头信息,供nginx分析
??? proxy_buffers 4 32k;??? ??? #保存几个buffer
??? proxy_busy_buffers_size 64k;??? #繁忙时申请更大的buffer
??? proxy_temp_file_write_size 64k;??? #缓存临时文件的大小
#??? gzip的配置(p63)
?server {
??????? listen?????? 80;
??????? server_name? localhost;
??????? location / {
??? ??? proxy_pass http://wan;
??? ??? proxy_redirect default;
??????? }
???
??? if(-d $request_filename){
??? ??? rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;
??? }
???
??? location ~ \.(jsp|do)?${
??? #?匹配0或者1词
??? ??? proxy_set_header Host $host;
??? ??? proxy_set_header X-Forwarded-For $remote_addr;
??? ??? proxy_pass 127.0.0.1:8080;
??? }
??? location? ~ .*\.(gif|jpg|jpeg|png|bmp|swf)${
??? ??? expires 30d;
??? }
??? location ~ .*\.(js|css)?${
??? ??? expires 1h;
??? }
??? }
???
??? 记录图片访问日志可能会导致日志很大。对日志的记录目前还没有关心过,可以参考日志切割。
----------------------




新浪的实际应用。
??? 新浪用嵌套域名在网页行,进行统计点击次数,打印日志。


proxy_set_header X-Forwarded-For $remote_addr;? #后端通过X-Forwarded-For获取用户真实ip。


if($request_url ~ "^\/app\/online\/"){
??? proxy_pass http://wan;
??? }


---------------------------------------------
error_page 404 502 502 http://wap.ttpod.com;
error_page 404 /404.html

keepalive_timeout 60;
连接持续时间,避免后续请求,可使用location server中。

limit_rate 100k;
限速功能
if(xx){
??? set $limit_rate 4k;
}
limit_rate_after 1m;
下载1M后自动限速


------------------------------------------------
location
??? = 优先
??? ~ 第二(同样的话按顺序)
??? /
??? 优先匹配字符串,----正则表达式。(按写的顺序)
---------------------------------------------------
server_name_in_redirect 重定向,已server_name 的第一个重定向, 或者已host重定向。

------------------------------------------------
HTTP Access 模块
??? 可以限制ip访问。
??? location /{
??? ??? allow 192.168.3.33 允许;
??? ??? deny 192.168.1.1 禁止;
??? }

---------------------------------------------------
cookie的使用
“Cooloe:PHPSSID=7fs78g6d87sg6sd7868sd7f6s8d7;userid=2”

$cookie_userid=2

if($http_cookie ~* "id=([^;] +)(?:;|$)"){
??? rewrite xxxxx
}



-----------------------------------------------------
还可以使用map和memcached
配置文件时 空格很重要



问题:
#linux下的模型????
??? use epoll;
记录日志
这里用到缓存的信息(第九章)
试验http_cookie(全局变量P109)(P212)
解决流量80M
proxy_buffers








热点排行