码迷,mamicode.com
首页 > 系统相关 > 详细

【 Nginx 】proxy_cache 模块的使用记录

时间:2016-05-19 19:11:07      阅读:218      评论:0      收藏:0      [点我收藏+]

标签:

部署环境:nginx + tomcat  同一台服务器。

  通过nginx反向代理tomcat。

  配置如下:

user  www www;
worker_processes  auto;

error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

pid        logs/nginx.pid;

worker_rlimit_nofile 65535;

events {
    use epoll;
    multi_accept on;
    worker_connections  2048;
}


http {
    server_tokens off;
    include       mime.types;
    default_type  application/octet-stream;

    log_format  main  $remote_addr - $remote_user [$time_local] "$request" 
                      $status $body_bytes_sent "$http_referer" 
                      "$http_user_agent" "$http_x_forwarded_for";

    access_log  logs/access.log  main;
    open_log_file_cache max=1000 inactive=15s min_uses=2 valid=5m;


    sendfile        on;
    tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;
    client_header_timeout 2m;
    client_body_timeout 3m;
    reset_timedout_connection on;
    send_timeout 15s;

    open_file_cache max=65535 inactive=20s;
    open_file_cache_valid 30s;
    open_file_cache_min_uses 2;
    open_file_cache_errors on;

    gzip  on;
    gzip_disable "msie6";
    gzip_proxied any;
    gzip_comp_level 4;
    gzip_min_length 1k;
    gzip_vary on;
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

    proxy_connect_timeout 300;
    proxy_send_timeout 300;
    proxy_read_timeout 300;
    proxy_buffer_size 16k;
    proxy_buffers 4 64k;
    proxy_busy_buffers_size 128k;
    proxy_temp_file_write_size 128k;
    proxy_cache_path /usr/local/nginx/cache/proxy_cache_dir levels=1:2 keys_zone=cache_one:200m inactive=1d max_size=30g;

    upstream backend_tomcat {
    server 10.0.10.5:10888 weight=1 max_fails=2 fail_timeout=30;
    }

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            #root   html;
            #index  index.html index.htm;
        #proxy_pass http://10.0.10.5:10888;
        proxy_cache cache_one;
        proxy_cache_valid 200 304 12h;
        proxy_cache_bypass $cookie_nocache $arg_nocache$arg_comment;
        proxy_cache_key $host$uri$is_args$args;
        proxy_pass http://backend_tomcat;
        #expires 1d;
        }
    
    #location ~ .*\.()

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apaches document root
        # concurs with nginxs one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
    include vhosts/*.conf;
}

  在此次配置中,使用到了proxy_cache模块,也因为这个模块造成了一个问题:

    用户通过页面登录系统,然后在通过页面按钮,点击退出。这时,如果点击浏览器的退后按钮技术分享 

    就会出现页面为登出系统的界面,刷新也是停留在登录后的页面,还可以进行一系列的操作。

    通过这个问题,我还是对proxy_cache模块的怀疑,是否proxy_cache对session也存在缓存的问题。

 

  再次修改配置文件,取消proxy_cache的使用,上述问题得到解决。如果proxy_cache模块对每个需要登录的网站都存在以上问题,那proxy_cache存在的必要是什么?

【 Nginx 】proxy_cache 模块的使用记录

标签:

原文地址:http://www.cnblogs.com/hukey/p/5509604.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!