免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 7265 | 回复: 4

[Web] 使用Nginx缓存和转发后,web功能失效的问题 [复制链接]

论坛徽章:
0
发表于 2011-06-22 14:51 |显示全部楼层
【问题描述】

我这边一个系统中,是使用一个js插件(http://johannburkard.de/blog/pro ... -jquery-plugin.html)实现将XML用XSL转换后显示信息的。

最近在原服务器前面加装了Nginx做缓存和转发,该代码就失效了。

请有经验的各位给点思路,可能是哪方面的原因。是不是我的Nginx配置有啥问题啊?

【环境描述】

应用服务器是Domino,端口8080,直接访问功能正常。

Nginx的端口80,经过其转发和缓存后,JS功能失效。

Nginx的配置文件如下:

  1. #user  nobody;
  2. worker_processes  3;

  3. error_log  logs/error.log;

  4. #Specifies the value for maximum file descriptors that can be opened by this process.
  5. worker_rlimit_nofile 1000;

  6. #pid        logs/nginx.pid;
  7. pid        logs/nginx.pid;

  8. #工作模式及连接数上限

  9. events {
  10.     worker_connections  1024;
  11. }

  12. #设定http服务器,利用它的反向代理功能提供负载均衡支持

  13. http {
  14.     include    mime.types;
  15.     default_type  application/octet-stream;   
  16.     charset utf-8;

  17.         #设定日志格式
  18.     log_format main    '$remote_addr - $remote_user [$time_local] '
  19.                          '"$request" $status $bytes_sent '
  20.                          '"$http_referer" "$http_user_agent" '
  21.                          '"$gzip_ratio"';

  22.     log_format download    '$remote_addr - $remote_user [$time_local] '
  23.                          '"$request" $status $bytes_sent '
  24.                          '"$http_referer" "$http_user_agent" '
  25.                          '"$http_range" "$sent_http_content_range"';

  26.   client_header_timeout  3m;
  27.   client_body_timeout    3m;
  28.   send_timeout          3m;
  29.         #设定请求缓冲
  30.   client_header_buffer_size    10k;
  31.   large_client_header_buffers  4 4k;

  32.         #设定访问日志

  33.     #access_log  logs/access.log  main;
  34.     access_log  logs/access.log main;

  35.     sendfile        on;
  36.     tcp_nopush      on;
  37.     tcp_nodelay     on;

  38.     #keepalive_timeout  0;
  39.     keepalive_timeout  15;

  40.   #注:proxy_temp_path和proxy_cache_path指定的路径必须在同一分区
  41.   proxy_temp_path   nginx_cache/proxy_temp_dir;
  42.   #设置Web缓存区名称为cache_one,内存缓存空间大小为200MB,1天没有被访问的内容自动清除,硬盘缓存空间大小为1GB。
  43.   proxy_cache_path  nginx_cache/proxy_cache_dir  levels=1:2   keys_zone=cache_one:200m inactive=1d max_size=1g;

  44. upstream  backend_server {  
  45.      server   127.0.0.1:8080;
  46. }


  47. #设定虚拟主机,默认为监听80端口,改成其他端口会出现问题

  48.     server {
  49.         listen       80;
  50.         server_name  _*;

  51.         #charset koi8-r;
  52.          charset utf8;
  53.          
  54.         #设定本虚拟主机的访问日志
  55.         access_log  logs/host.access.log  main;

  56.                 index index.html index.htm;

  57.         location ~ \.(htm|html|asp|php|gif|jpg|jpeg|png|bmp|ico|rar|css|js|zip|java|jar|txt|flv|swf|mid|doc|ppt|xls|pdf|txt|mp3|wma|xsl)$ {
  58.    
  59.         proxy_pass http://backend_server;   
  60.         proxy_set_header Host $host;   
  61.         proxy_set_header X-Real-IP $remote_addr;   
  62.         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;   
  63. #        expires 24h;
  64.                                 expires 15m;
  65.             
  66.         #进行缓存,使用Web缓存区cache_one   
  67.         proxy_cache cache_one;
  68.    
  69.         #对不同HTTP状态码缓存设置不同的缓存时间   
  70.         proxy_cache_valid 200 1m;
  71.         proxy_cache_valid 304 1m;
  72.         proxy_cache_valid 301 302 1m;
  73.         proxy_cache_valid any 1m;
  74.    
  75.                 #设置Web缓存的Key值,Nginx根据Key值md5哈希存储缓存.
  76.         #以域名、URI、参数组合成Web缓存的Key值,Nginx根据Key值哈希,存储缓存内容到二级缓存目录内
  77.         proxy_cache_key $host$uri$is_args$args;
  78.    
  79.         }

  80.         location / {
  81.             #root   html;
  82.             #index  index.html index.htm;
  83.             #其余的不缓存   
  84.             proxy_set_header Host $host;   
  85.             proxy_set_header X-Real-IP $remote_addr;   
  86.             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;   
  87.             proxy_pass http://backend_server;   
  88.         }

  89.         #error_page  404              /404.html;

  90.         # redirect server error pages to the static page /50x.html
  91.         #
  92.         error_page   500 502 503 504  /50x.html;
  93.         location = /50x.html {
  94.             root   html;
  95.         }
  96.     }
  97. }
复制代码

论坛徽章:
0
发表于 2011-06-22 14:57 |显示全部楼层
补充一下,尝试过不用插件,改为直接写JS代码(代码2)实现对XML数据用XSL处理后显示出来的功能。
也是在直接访问8080端口时功能正常,经Nginx的80端口去访问就不行了。


代码2:
  1. var source = new ActiveXObject("Msxml2.DOMDocument");
  2.    var style = new ActiveXObject("Msxml2.FreeThreadedDOMDocument");
  3.    var XSLt=new ActiveXObject("Msxml2.XSLTemplate");     
  4.    source.async = false;
  5.    style.async = false;
  6.    source.resolveExternals = false;
  7.    style.resolveExternals = false;
  8.    source.load(path+"(XMLViewForHomePage)?ReadViewEntries&count=10");       
  9.    style.load("/webOA/xsl/xslForPortal_sy.xsl");
  10.    XSLt.stylesheet = style;
  11.    ProcSetParam = XSLt.createProcessor();
  12.    ProcSetParam.input = source;  
  13.    ProcSetParam.transform();
  14.    var vHTML=ProcSetParam.output;
复制代码

论坛徽章:
0
发表于 2011-06-23 16:08 |显示全部楼层
自己顶一下 & 继续测试中。

论坛徽章:
0
发表于 2011-06-25 15:52 |显示全部楼层
自己顶一下 & 继续测试中。

论坛徽章:
0
发表于 2011-07-11 14:31 |显示全部楼层
检查一下是否开启了gzip压缩。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP