Server

How to enable WSGIPassAuthorization in NGINX + DJango

12 Aug , 2015  

Just in case we need to enable “WSGIPassAuthorization” in NGINX, we can put this in nginx hosts

1
2
3
4
5
proxy_pass_request_headers on;
proxy_no_cache $cookie_nocache  $arg_nocache$arg_comment;
proxy_no_cache $http_pragma     $http_authorization;
proxy_cache_bypass $cookie_nocache $arg_nocache $arg_comment;
proxy_cache_bypass $http_pragma $http_authorization;

Server

Change / Reset / Update Key Pem Amazon EC2 Simple

19 Feb , 2015  

Here are simple tricks to change or update key PEM in Amazon EC2. At this example, I’m using Ubuntu.
To reset or change key pem, all you need just follow this simple steps:

Let say, currently we have SERVER_01 and KEYPEM_01.

1
2
3
4
5
6
1. Launch a new instances using "launch more like this" (right-click on instances)
2. Create a new server SERVER_02 and new keypem KEYPEM_02
3. Copy your KEYPEM_01 into SERVER_02 using "rsync"
4. Login into SERVER_02, then "rsync" ".ssh/authorized_keys" to SERVER_01 "/.ssh/authorized_keys"
5. Basically, we just replace the "authorized_keys" from new to old
6. We can login to SERVER_01 using KEYPEM_02

Simple! :D

Server

Set Postgresql open for remote access in EC2

12 Dec , 2014  

To make PostgreSQL can be accessible from remote, first in EC2 security, please open your port “5432″ (if your installation is using default port).

Next, we need to edit pg_hba.conf :

/etc/postgresql/9.3/main/pg_hba.conf and add :

1
host    all             all             0.0.0.0/0               md5

Restart your services and test by

1
psql -h server-ip -U username -d database_name

Server

Setup Git in Windows 8

4 Oct , 2014  

Here are quickstep to setup git in windows :

1. Download git from http://git-scm.com/download/win
2. In Installation, make sure to enable git and linux command in command prompt (yes, the red text)

Now, git can be accessed from your command prompt. Next step is generate ssh key for windows.

Go to git bash (you can search in windows menu) and execute

1
ssh-keygen -t rsa -C "your-email"

Now, you can find the public key in C:\Users\\.ssh\

Server

Import PostgreSQL database

27 Aug , 2014  

Simple syntax to import postgreqsl database :

1
psql -U <username> -h localhost -d <database_name> < dump_data.sql

Server

Solve VSFTPD error retrieving directory Ubuntu

16 May , 2014  

Suddenly i got this “error retrieving directory, connection timeout ..” when accessing ftp EC2 server. Then, the solution just change my FTP client from “passive mode” into “active mode”. Weird but works!

Server

Set EBS as root partition on EC2

29 Apr , 2014  

We can replace main partition in EC2 using EBS for larger space. Make sure to use HVM instead of Paravirtual.
First thing, we need to create a new EBS and attach it into running instance. Now, we should login into our SSH server.

1. Copy old instance into new instance
Find what your root partition and new ebs partition by “sudo fdisk -l”. At this example, mine is “/dev/xvda1″ for current main partition and new ebs at “/dev/xvde”. So, i need to clone from current main partition into new ebs.

1
dd bs=65536 if=/dev/xvda1 of=/dev/xvde

2. Check new partition

1
2
3
sudo fsck /dev/xvde
sudo e2fsck -f /dev/xvde
sudo resize2fs /dev/xvde

3. Installing
We need to stop the instance, detach all ebs partition. Then re-attach new ebs partition into instance with mount point into “/dev/sda1″. Re-associate your elastic IP (if any) and start instance.

Server

Simple MySQL command to show tables and row counts

25 Mar , 2014  

Here is simple mysql syntax to show tables with row counts :

1
select table_name, table_rows from information_schema.tables where table_schema = "YOUR_DATABASE_HERE";

Server

Solve gitignore not working windows

13 Jan , 2014  

The solution gitignore not working windows

1
2
3
git rm -r --cached .
git add .
git commit -m ".gitignore is now working"

For android, .gitignore can be :

1
2
3
4
gen/
bin/
project.properties
.gitignore

Server

Solve [error] 28901#0: *401 upstream sent too big header while reading response header from upstream

9 Dec , 2012  

Today I got this 502 error on my websites :

1
Solve [error] 28901#0: *401 upstream sent too big header while reading response header from upstream, client: 116.86.214.27, server: yodi.biz, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "yodi.biz"

After looking at NGINX documentation, i found the problem in my fastcgi buffers. So, the solution is just open /etc/nginx/nginx.conf and on “http” part, put this :

1
2
fastcgi_buffers 8 16k;
fastcgi_buffer_size 32k;

If you still get 502 upstream sent too big header, then try to increase the fastcgi buffers :)

,

Server

Install LXML in Debian

26 Nov , 2012  

To install LXML python module in Debian, you need to install depedency packages :

1
apt-get install python-dev libxml2 libxml2-dev libxslt1-dev libbz2-dev libssl-dev p7zip-full rar lha unrar unzip unace unp bzip2 gzip patch

Then, you can install lxml by :

1
pip install lxml

Server

Solve slow DNS in HpCloud due to double reload on the website

24 Sep , 2012  

I found something weird with my Bind in HPCloud which it’s working well in my EC2. After trying several experiment, I found the correct way to set bind in HPCloud. This is for example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
;
; BIND data file for local loopback interface
;
$TTL    3600
@       IN      SOA     obroll.com. admin.obroll.com. (
                             30        ; Serial
                         604800         ; Refresh
                          86400         ; Retry
                        2419200         ; Expire
                         604800 )       ; Negative Cache TTL
;
obroll.com  IN  A       15.185.178.20
@       IN      NS      ns1.obroll.com.
@       IN      A       15.185.178.20
ns1     IN      A       15.185.178.20
ns2     IN      A       15.185.178.20
www     IN      A       15.185.178.20

Yes, I put my domain name as first :)

Server

Solving Bind DNS un-resolved when nslookup domain without WWW

13 Sep , 2012  

This is common mistake when we try to nslookup our domain that working with “WWW” but not without “WWW”. This is some bind9 configuration :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
;
; BIND data file for local loopback interface
;
$TTL    3600
@       IN      SOA     obroll.com. admin.obroll.com. (
                             30        ; Serial
                         604800         ; Refresh
                          86400         ; Retry
                        2419200         ; Expire
                         604800 )       ; Negative Cache TTL
;
@       IN      NS      ns1.obroll.com.
ns1     IN      A       15.185.178.20
ns2     IN      A       15.185.178.20
www     IN      A       15.185.178.20

More…

,

Server

How to install and uninstall sphinx search from source in Ubuntu

3 May , 2012  

Instead using synaptic and install sphinxsearch deb package, we also can use the source. First, you should download source package from the sphinxsearch website http://sphinxsearch.com/downloads/.

At this example, I use sphinx-2.0.4-release.tar.gz. I use Ubuntu 12.04 Precise. Then you can extract it and start compiling. Here are the steps to do :

1
2
3
4
5
6
sudo apt-get install build-essential libmysql++-dev libmysqlclient18-dev
tar -xvvf sphinx-2.0.4-release.tar.gz
cd sphinx-2.0.4-release
./configure --with-mysql
make
sudo make install

It will installed in /usr/local. For sphinx.conf, you can create it at /usr/local/etc.

If you need to uninstall sphinx search from source, then just go to previous folder (sphinx-2.0.4-release) and do :

1
sudo make uninstall

,

Server

NGINX *1 upstream sent too big header while reading response header from upstream

20 Mar , 2012  

When I login into WordPress Administration page, I got it blank pages. Curious about what happend, I go through into NGINX error.log and I see this error :

1
*1 upstream sent too big header while reading response header from upstream

Then to solve this problem, I need to add “fastcgi_buffers 8 256k;” and “fastcgi_buffer_size 128k;” this into my nginx hosts :
More…

,

Server

Solve recv() failed (104: Connection reset by peer) 502 NGINX Bad Gateway PHP5 FPM

19 Mar , 2012  

When I host many wordpress sites under NGINX + PHP5-FPM on Ubuntu Oneiric, everything is smooth and there no problem. Suddenly, after a few month, I got error NGINX 502 Gateway on my cron. Then after dive into NGINX error.log, I see this error :

1
2
2012/03/19 14:20:21 [error] 2383#0: *334 readv() failed (104: Connection reset by peer) while reading upstream, client: 199....., server: www.clipsta.com, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "www.clipsta.com"
2012/03/19 14:21:18 [error] 2899#0: *19 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 103.2..., server: www.clipsta.com, request: "GET /wp-cron.php?doing_wp_cron HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "www.clipsta.com"

More…

,

Server

Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’

15 Mar , 2012  

Do you got several error message like this ?

1
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'

Or

1
[ERROR] /usr/sbin/mysqld: Incorrect key file for try to repair it

Or maybe :

1
sudo service mysql start start: Job failed to start

More…

,

Server

How to open PostgreSQL remote access with IP address limitation on Ubuntu

14 Feb , 2012  

When trying to configure postgresql to be able accessed remotely from another IP address, we usually got several errors like this :

1
2
3
4
postgresql remote access no pg_hba.conf entry for host

psql: FATAL:  no pg_hba.conf entry for host "xxxxx", user "xx", database "xxxx", SSL on
FATAL:  no pg_hba.conf entry for host "xxxx", user "xx", database "xxx", SSL off

OR

1
" FATAL: no pg_hba.conf entry for host"

To make PostgreSQL in Ubuntu 11.10 can be accessed from remote, follow this path :

Edit this files :

1
sudo vim /etc/postgresql/9.1/main/postgresql.conf

Line 59:

1
listen_addresses = '*'          # what IP address(es) to listen on;

More…

,

Server

Awk sed total bot access.log Apache Ubuntu

6 Feb , 2012  

We can mining and calculate Bot from access.log Apache2 using awk and sed. To get rank and total list of Bot that visit our webpages, then go to “/var/log/apache2″ and this scripts :

1
awk '{print $12}' access.log.1 | sort | uniq -c | sort -nr

More…

,

Server

How to create user postgresql using Pgadmin Ubuntu

6 Feb , 2012  

Create postgresql new user using Pgadmin in Ubuntu is very easy. First, launch your Pgadmin that used “postgres” account and connect into localhost. Then, after login, expand your “localhost” item and find “Login Roles“.

Right click on “Login Roles”. Then create your users and setup the permission.

,

Server

How to reset postgres password in PostgreSQL Ubuntu 11.10 Oneiric

6 Feb , 2012  

Reset postgres user password in PostgreSQL Ubuntu 11.10 Oneiric is very simple. First, make sure you have set trust mode in pg_hba.conf ( /etc/postgresql/9.1/main/pg_hba.conf ), for instance :

1
2
3
4
5
6
local   all             postgres                                trust

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     trust

More…

,

Server

Example how to git submodule, add, delete submodule and use existed git repository

2 Feb , 2012  

Git submodule is great feature on Git which it will needed much on large projects than build by small parts. For example, I have single project called “Insurance”. This project contains several apps like “billing”, “user”, “backend” and several apps. We want to create single repository that contain several small repositories.

Using git submodule will ease for integration with several programmer or applications. In this example, I use gitolite which you can follow this article to Install Gitolite in Ubuntu. I will create 3 repositories called “insurance”, “billing” and “user”.
More…

,

Server

How to Virtualbox Guest share wireless connection from host Ubuntu

30 Jan , 2012  

I usually use LAN cable and share internet connection using NAT to Virtualbox client. But, I need to connect using Wireless int my Host and found NAT can’t works through this connection. So, share internet connection from wireless to Virtualbox guest, we should use “bridge-network”.

Go Virtualbox Client Settings -> Network -> Bridge network and choose your wireless devices.
Then start your Virtual Machine and set cable connected on network icon.

,

Server

Solve cannot create /etc/ssh/sshd_config: Directory nonexistent deleted ssh folder Ubuntu

24 Jan , 2012  

Today I made mistake by deleting “/etc/ssh” folder manually. Then when I try to re-install openssh-server in Ubuntu Oneiric, it gave me several errors like this :

1
2
3
4
5
6
7
8
9
10
11
12
13
/var/lib/dpkg/info/openssh-server.postinst: 456: cannot create /etc/ssh/sshd_config: Directory nonexistent
dpkg: error processing openssh-server (--configure):
 subprocess installed post-installation script returned error exit status 2
dpkg: dependency problems prevent configuration of ssh:
 ssh depends on openssh-server; however:
  Package openssh-server is not configured yet.
dpkg: error processing ssh (--configure):
 dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
                                                                                                          Errors were encountered while processing:
 openssh-server
 ssh
E: Sub-process /usr/bin/dpkg returned an error code (1)

More…

,

Server

How to login postgresql access psql from ubuntu user

11 Jan , 2012  

I use Ubuntu 11.10 Oneric and Postgresql 9.1 in this cases. So, when I need to dump database using “psql -U postgres” from ubuntu, I got several error like this :

1
2
3
psql: FATAL:  role "ubuntu" does not exist
psql: FATAL:  Peer authentication failed for user "postgres"
psql: FATAL:  Peer authentication failed for user "postgres"

More…

,

Server

WordPress NGINX configuration solve gateway timeout

8 Jan , 2012  

You facing NGINX gateway timeout in wordpress. You already change php.ini and increase timeout but not solve the problem yet. Also, you increase timeout in HAProxy and not results yet. Then the problem come inside NGINX. Some cases it’s happen because Fast CGI timeout is so tight. Also, it because client response timeout also small.

Here are example how to increasing timeout in NGINX for our WordPress :
More…

,

Server

How to make ssh into server without password

7 Jan , 2012  

This is mostly needed by beginner network admin which login into several server from their laptop / PC and inserting password each login. We can avoid this inserting password by using public keys. Now, go to client and generate public key by :

1
ssh-keygen -t rsa

More…

,

Server

Setup VPS / Server from beginning for WordPress sites with NGINX + MySQL Ubuntu

27 Dec , 2011  

I will guide you about how to setup brand new VPS / Server to host WordPress with optimize configuration. I prefer use NGINX + MySQL here. Remember, I start from zero configuration with mean no software installed , no pre-installed program and default Ubuntu. If you want to install several VPS / Server, then you can try “terminator” console and set broadcast.
More…

,

Server

How to ping and SSH Ubuntu Guest Host Virtualbox

16 Sep , 2011  

By default SSH & ping between Virtualbox Guest and Host is disabled. Virtualbox make NAT connection between Host and Guest so we can have internet connection in Guest. To make Host and Guest can communicate in two ways, here are the steps :

1. Create vboxnet0 network device.
If you don’t have this vboxnet, you will have empty in Network Adapter preferences.
So, open Virtualbox and go ” File -> Preferences -> Network “.

Add host-only by press + (plus) button.
More…

,