Saturday, December 26, 2015

Block all 404 errors

Recently, I found huge amount of 404 error which cause my server CPU to 100%. Most of the 404 errors are come from several IP addresses.

Firstly I installed iptables to block them out:

iptables -A INPUT -s %SOME-IP-ADDRESS% -j DROP

After doing this, to save it, you need to run

service iptables save

Later, I want to find some way to automatically block them out, I found fail2ban.

After simply install fail2ban, you need to create a file called jail.local to put settings in:

[DEFAULT]
ignoreip = 127.0.0.1/8 %SOME MORE IP IF YOU LIKE%
bantime  = 3600

[apache-script-bots]
enabled  = true
port     = http,https
logpath  = %(apache_access_log)s
maxretry = 5

This means if someone tries for 5 times 404 error, there IP address will be banned for 1 hour.

You also need to put a file called apache-script-bots.conf in filter.d folder:

[Definition]
failregex = ^ .* 404 .*$
ignoreregex =

This setting tell fail2ban to check Apache access log to find all the 404 errors.

Friday, November 27, 2015

Abandon git local branch

I've merged, I've commited changes locally, but I have not decided to push it or not, so I leave it there. After several days, I want to totally abandon my local branch.

I would do below:

  1. git checkout master
    It will just tell you that your local branch is different from remote.
  2. git reset --hard origin/master
    This is the real effect command, it will force your local to be exactly same as remote.

Friday, October 30, 2015

Wordpress posts show question marks

I installed Wordpress on my local server, when I moved it onto remote server, all posts show just question marks like this:

?????

What I did was: mysqldump, then mysql in.

Later after lots of search, inspired by this post:

https://mathiasbynens.be/notes/mysql-utf8mb4 

I found all I need to do is to set remote database server to use utf8mb4.

Be careful, all database, tables and columns by the newest Wordpress are already utf8mb4, so I did not touch them. Just to this to change your mysql database server to use utf8mb4. Every line is needed:

[client]
default-character-set=utf8mb4

[mysql]
default-character-set=utf8mb4

[mysqld]
character-set-client-handshake=FALSE
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci

Especially this line:
character-set-client-handshake=FALSE

I don't know why Wordpress php need this line, but it do have effect. If someone know, please let me know. Thanks!

Search

Google