English 中文(简体)
nginx/redis and handling tracking params in url
原标题:

I am using nginx and redis in my website. For several items on my site, I want to add tracking params to their urls so that when a user clicks on an item, I can collect statistics of user usage apart from serving the content user requested. I am looking for methods on how to capture this statistics in redis from nginx, i.e. without hitting the background application.

For eg., suppose I have several rows of tables on my page and each table hold items in row/column format. So, for an item in {table: 2, row: 1, column: 3} if the actual url is: www.mysite.com/news/dodi, then I want to embed the url: www.mysite.com/news/dodi/day=29?table=2&row=1&column=3. When the user clicks on it, nginx will hit redis to fetch the content and also update the appropriate statistics (here can be increment day-29, table-2, ...).

Any suggestion on how I achieve this without hitting the background app?

最佳回答

For the tracking parameters, keep this type of work outside the scope of the users request. Don t make them pay the latency penalty for stats tracking. Cron a script that extracts the parameters from access.log and updates redis and/or database.

In terms of caching content, there is a recently released nginx redis module that works in much the same way as the memcached module. Only GET and SELECT are presently implemented. The assumption is that your application is populating the cache.

http://wiki.nginx.org/Nginx3rdPartyModules#HTTP_Redis_Module

Sample nginx.conf:

http
{
 ...
        server {
            location / {
                set $redis_db   "0";
                set $redis_key  "$uri?$args";
                redis_pass      127.0.0.1:6379;
                error_page      404 502 504 = @fallback;
             }

             location @fallback {
                 proxy_pass      backed;
             }
        }
}
问题回答

暂无回答




相关问题
Using PHP to find part of a URL

Take this domain: http://www.?.co.uk/elderly-care-advocacy/mental-capacity-act-advance-medical-directive.html How could i use PHP to find the everything between the first and second slash regardless ...

Domains & Foreward Slash

This is rather difficult to explain so please bear with me. We will be hosting 4 websites on our server and the plan is to have each site sit under its own domain: site-a.com site-b.com sub1.site-b....

Encoding of window.location.hash

Does window.location.hash contain the encoded or decoded representation of the url part? When I open the same url (http://localhost/something/#%C3%BC where %C3%BCtranslates to ü) in Firefox 3.5 and ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

采用网路服务方法

我撰写了一个网络服务,期望一个参数(所谓的“hlink”)成为一种ur。 在使用网络服务之前,URLEncode 所涉参数(“hlink”)。 然后我打电话......。

热门标签