Nginx configuration for WordPress websites

If you are using the WP Super Cache plugin by Automattic, this configuration can help you settings up your Nginx caching proxy:

[code]proxy_cache_path /data/nginx/cache keys_zone=one:10m inactive=24h max_size=1G;
proxy_cache_key “$host$request_uri$cookie_user”;
proxy_cache one;

server {
server_name ~^(static\.)?(?.+)$;
access_log /var/log/nginx/domains/static.$domain.log;

location ~ ^/(wp-content|wp-includes)/ {
resolver 8.8.8.8;
expires 30d;
add_header Pragma public;
add_header Cache-Control “public”;
proxy_cache_valid 200 10m;
proxy_pass http://www.$domain;
add_header X-Cache-Status $upstream_cache_status;
}
}[/code]

Change the static.domain.com to the hostname the nginx server is listening to. Change domain.com (twice!) to the main domain where the content is pulled from.

Make a DNS record (either cname or a) pointing static.domain.com to the IP the nginx server is running at.

Be sure to chmod the /data/nginx/cache folder to 700 and change the ownership to the same user as nginx is running (default nginx).

Check if the cache is working by using this command:

[code]du -h –max-depth=1 /data/nginx/cache[/code]

Easy as that!

Remove e-mail sent count from e-mailaccount

If you want to reset the e-mail acount of a DirectAdmin account it’s pretty simple, you can just hit the reset button. But there are no such buttons for the e-mail accounts itself. So you can use this little line in SSH to remove the e-mail sent acount of a particular e-mail account:

rm -f /etc/virtual/domain.com/usage/info

Notice this line concerns info@domain.com. So you have to change the domain.com part and the info part.

Adding domain pointer with e-mail and SSL options

If you add a domain pointer to a DirectAdmin domain, you can not set-up the e-mail accounts and SSL certificates by default. Almost all the options are not available.

To fix this you can remove the domain pointer and add the domain as a normal domain to the account. It has to be the same account due to permissions.

Then, remove the private_html folder, symlink it to the public_html and set the correct permissions with this piece of code:

rm -rf /home/user/domains/domain.com/private_html
ln -s /home/user/domains/domain.com/public_html /home/user/domains/domain.com/public_html
chown -h user:user /home/user/domains/domain.com/public_html

Now you have the same effect of the normal Domain Pointer in DirectAdmin, but you are able to use the interface for all other DirectAdmin options!

Extending HP smartarray with hpacucli

If you are trying to expend a raidset on a system with HP storage controllers you can use this.

Please note: you need to have a BBWC if you want to expand an array.

First check if the disks you added are detected:

hpacucli ctrl all config show

If you see the disks at the unassigned section we are good to go.

hpacucli ctrl slot=0 array A add drives=allunassigned

Get the slot and array information from the first output.
The expansion can take up allot of time. This is al depending on disk size and performance.

If the first process is done we need to set the logical disk to max space.

hpacucli ctrl slot=0 ld 1 modify size=max

If this is all done you probably need to expend your partition as well.

I would say, google is your friend!

 

Fix domains list in DirectAdmin

I don’t know why, but at one of my servers the domains.list file gets erased every x weeks. So after some weeks they are missing in the httpd.conf and the domains will not work.

Before I figure out what causes it, this is a little piece of code to fix the list and rewrite httpd:

for d in `ls /home/user/domains`; do echo $d >> /usr/local/directadmin/data/users/user/domains.list; done
/usr/local/directadmin/custombuild/build rewrite_confs

Reset per e-mail account usage limit in DirectAdmin

Since DirectAdmin works with ‘per e-mail account send limits’ some things can work out pretty annoying.

In this case the customer sent 1000 e-mails (not SPAM) and want to send e-mail number 1001. But, changing the limit to 2000 will result in a

Please set a limit between 1 and 1000

Despite the fact of the “Zero is unlimited”, if you enter 0 it will give:

You cannot set an unlimited send limit

So I ended up to search in the files and remove the usage by hand:

rm -f /etc/virtual/domain.com/usage/info

Now the usage is removed and the customer is able to send another 1000 e-mails. Which still is not solved but for now it’s done.

Small sed cheatsheet

Sed is a brilliant function to delete or replace strings. I often used sed for replacing (a group of) words or deleting lines.

How to remove a line containing a string in sed:

sed -i '/string/d' /home/admin/filename.txt

How to replace a string in sed:

sed -i 's/#Port 22/Port 12340/g' /etc/ssh/sshd_config

How to remove white lines from ie a .ini file with sed:

sed -i '/^\s*$/d' /usr/local/directadmin/conf/directadmin.conf

Bash commands to see server stats

I found this little snippet elsewhere and find it very usefull to use in my own scripts for statistiscs:

free -m | awk 'NR==2{printf "Memory Usage: %s/%sMB (%.2f%)\n", $3,$2,$3*100/$2 }'
df -h | awk '$NF=="/"{printf "Disk Usage: %d/%dGB (%s)\n", $3,$2,$5}'
top -bn1 | grep load | awk '{printf "CPU Load: %.2f\n", $(NF-2)}'

It returns something like:

Memory Usage: 2340/24000MB (9.75%)
Disk Usage: 40/100GB (40%)
CPU Load: 0.04

Bash script to make MySQL back-ups

This simple but effective script makes a back-up of the target SQL database and deletes databases older then 90 days. I keep the folder synchronized with other systems so the customer can reach his database with 90 days retention himself.

#!/bin/bash

cd /backups

user="mysql_user"
passwd="password"
host="localhost"
db_name="mysql_database"

backup_path="/backups"
date=$(date +"%d-%b-%Y")

umask 177

# dump the database
mysqldump --user=$user --password=$passwd --host=$host $db_name > $backup_path/$db_name-$date.sql

# zip contents
zip $db_name-$date.zip $db_name-$date.sql

# remove old backups
find $backup_path/* -mtime +90 -exec rm {} \;

echo done

 

Of course, instead of setting the username/passwd variables in the script itself you can read the DirectAdmin credentials with:

source /usr/local/directadmin/conf/mysql.conf