Nginx Openresty Get/Set Cookies using LUA.

To set cookies using lua while using nginx_lua module in openresty/nginx server, use this code: local expires = 3600 * 24  — 1 day ngx.header["Set-Cookie"] = “session=demo; Path=/; Expires=” .. ngx.cookie_time(ngx.time() + expires) This will set cookie session = demo for 1 day from current time on path...

Use PHP Functions in LUA Code

explode Based on [PHP explode] Example: explode(” and “,”one and two and three and four”) –> {“one”,”two”,”three”,”four”} Compatibility: Lua 5.0 and 5.1function explode(div,str) if (div==”) then return false end local pos,arr = 0,{} – for each divider found for st,sp in function() return...

Purge redis keys in matching pattern

After logging in to linux shell execute this command redis-cli KEYS “*$1*” | xargs redis-cli DEL where $1 is the argument/string which you need to find. E.g.   redis-cli KEYS “*test*” | xargs redis-cli DEL where test is a string you need to search for.  

Mysql get size of tables in a database

To find the detail of size of tables in a database use this query in mysql console: SELECT table_name AS “Tables”, round(((data_length + index_length) / 1024 / 1024), 2) “Size in MB” FROM information_schema.TABLES WHERE table_schema = “$DB_NAME” ORDER BY (data_length + index_length) DESC; E.g. for database name mydatabase : SELECT table_name AS...

Nginx Proxy requests are redirecting to upstream name.

If you are using nginx as a reverse proxy and having the redirection issues to upstream name when proxy request results in 301,302 redirects, e.g. http://www.mind-geek.net/new.html is proxied by backend upstream i.e. upstream backend { server; } location / { proxy_pass http://backend; } and the requests are getting ended eith http://backend/new.html, than you need to sepecify the...

How to add indexer in a Custom Module?

Follow these steps: config.xml: <index>                        <indexer> <cms_indexer> <model>module/cmsindexer</model> </cms_indexer> </indexer> </index> Model: app/code/local/Name/Module/Model/Cmsindexer.php Class Module_Model_CmsIndexer extends Mage_Index_Model_Indexer_Abstract { public function getName(){ return ‘Add CMS...

What is configure, make, make install ?

There are lot of confusions for usual configure, make, make install sequence to get a program running in Linux. Unfortunately, most developers today have never used a compiler to install an application and used the GUI application builders. The make utility is designed to decrease a programmer’s need to remember line of commands. I guess that is actually the good way of saying, it decreases a...

How to Enable Password Authentication in Amazon EC2 Instances?

Edit the ssh configuration file - # vim /etc/ssh/sshd_config Change PasswordAuthentication to yes from no to enbable login via clear text passwords. Here is the snippet: # Change to no to disable tunnelled clear text passwords PasswordAuthentication yes Save and close the File. Restart ssh service – service sshd restart Voila, Now, you can login using the user account and passwords on same...

Set timezone of Mysql Server

Many times timezone issues with your database server causes wrong information to be entered in reports, transaction tables etc. To fix timezone issues with your mysql server, just login to your mysql and execute following query: SET GLOBAL time_zone = ‘<REQUIRED TIMZONE>; E.g. SET GLOBAL time_zone = ‘+5:30′; If you have to get the  current timezone, use this- SELECT TIMEDIFF(NOW(),...

Nginx show/set real ip address(public) from Amazon ELB Load Balancer address

To make it work, we need to add following lines to nginx configuration file: real_ip_header X-Forwarded-For; set_real_ip_from; It makes nginx to trust an X-Forwarded-For header from anyone, which makes Real Ip visible on logs and can be used in other programs where real ip is required.

« Previous Entries