cache – 如何使用nginx作为缓存反向代理来替换squid/varnish

前端之家收集整理的这篇文章主要介绍了cache – 如何使用nginx作为缓存反向代理来替换squid/varnish前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

以下是我们目前在应用程序上的设置

但我们想将Nginx添加为反向代理缓存,就像鱿鱼或清漆一样
是否可以编辑此配置以启用该缓存行为,或者我是否需要在此设置前添加另一个Nginx,就像我对鱿鱼或清漆所做的那样

如果这可以在不使用鱿鱼和清漆的情况下完成,那么在Nginx中进行完整的设置会很不错

非常感谢

upstream backend_appname{
     #start1.someserver.com
     server start1.someserver.com:7810 fail_timeout=3s;
     server start1.someserver.com:7811 fail_timeout=3s;
     server start1.someserver.com:7812 fail_timeout=3s;
     server start1.someserver.com:7813 fail_timeout=3s;


}
server {
    server_name  appname.someserver.com;
    listen 80;
    access_log   logs/access_appname.log;
    #error_log   logs/error_appname.log;

    location /Nginx_status {
        stub_status on;
        access_log   off;
    }

    location /static {
        root   /home/someuser/work/appname;
        expires max;
        add_header Cache-Control public,max-age=604800,post-check=604800,pre-check=1209600;
    }
    location / {
        root   /home/someuser/work/appname;
        fastcgi_pass backend_appname;
      set  $addr  $remote_addr;

     if ($http_x_forwarded_for ~ "(?:^|,)\s*(\d+\.\d+\.\d+\.\d+)\s*$") {
           set  $addr  $1;
     }

        fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
        fastcgi_param PATH_INFO       $fastcgi_script_name;
        fastcgi_param QUERY_STRING    $query_string;
        fastcgi_param CONTENT_TYPE    $content_type;
        fastcgi_param CONTENT_LENGTH  $content_length;
        fastcgi_param REQUEST_METHOD  $request_method;
        fastcgi_param REMOTE_ADDR     $addr;
        fastcgi_param REMOTE_PORT     $remote_port;
        fastcgi_param SERVER_PROTOCOL $server_protocol;
        fastcgi_param SERVER_ADDR     $server_addr;
        fastcgi_param SERVER_PORT     $server_port;
        fastcgi_param SERVER_NAME     $server_name;

    }

}
最佳答案

猜你在找的Nginx相关文章