Password protecting a site in nginx

This post will explain how to password protect a site in nginx. It is very simple and it uses the normal htpasswd protection

Suppose I need to password protect the site abc.com whose document root is /var/www/abc/public_html

Simple follow the steps given below

[root@abc ~]#  cd /var/www/abc/public_html

[root@abc ~]#  htpasswd -c .htpasswd admin        where admin is the username chosen. It will prompt for password, give a strong password.

Now, your login details are stored to the file /var/www/abc/public_html/.htpasswd and we need to call this file from abc.com’s conf.

Simply add the following two lines before the locations

[root@abc ~]# cd /etc/nginx/sites-available/

[root@abc ~]# vi abc.com

auth_basic “Restricted”;
auth_basic_user_file /var/www/abc/public_html/.htpasswd;

 

So your final conf will now look as follows.

server {
server_name www.abc.com abc.com;
access_log /var/www/abc/logs/access.log;
error_log /var/www/abc/logs/error.log;
root /var/www/abc/public_html/;

auth_basic “Restricted”;
auth_basic_user_file /var/www/abc/public_html/.htpasswd;

location / {

index index.html index.htm index.php;

}

location ~ \.php$ {
if (!-e $request_filename) { rewrite / /index.php last; }
include /etc/nginx/fastcgi_params;
fastcgi_pass  127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME  /var/www/abc/public_html$fastcgi_script_name;
fastcgi_param MAGE_RUN_CODE base;
fastcgi_param MAGE_RUN_TYPE website;

}
}

All done, save the configuration file and exit. Now restart nginx and see if it starts without errors.

[root@abc ~]# /etc/rc.d/init.d/nginx restart
Stopping nginx:                                            [  OK  ]
Starting nginx:                                            [  OK  ]

Now clear your browser cache and try accessing the site. Bingo!! isnt’t it protected? :-)

MongoDB backup/restore

Want to know how the backup of mongo database can be taken. Read below…

Four tools are described here.

1) mongoexport

mongoexport can be used to take the backup of a mongo database. It takes the backup to a CSV, TSV or JSON files. The syntax is as follows.

mongoexport -d db_name -c test -o db_name.csvwhere -d is the database name
-c is the collection name
-o is the file name to which the backup is to be taken

2) mongoimport

mongoimport can be used to import a backup to a database. You can import from the backup file as follows.

mongoimport -d db_restore -c test –file db_name.csvwhere -d is the name of the database to which the file is to be restored
-c is the collection name
–file is the backup file

3) mongodump

For those who need a complete backup of the database, you can use mongodump command to do so. Unlike mongoexport, the backup will be done into a folder and not file.

mongodump -d db_test -o /backuptestwhere -d is the database name
-o is the folder to which data is to be backed up

Once completed, the backup will be present in /backuptest/db_test/

4) mongorestore

To restore an entire database, you can use the mongorestore command. Let’s restore the backup that we took in the previous step.

mongorestore -d db_test_restore /backuptest/db_test/where -d is the existing or new database to which the data is to be restored
and the folder /backuptest/db_test/ is where the backup of db_test exists.

Try it and see, it works :-)

WARNING: You are running on a NUMA machine We suggest launching mongod like this to avoid performance problems: ** numactl –interleave=all mongod [other options]

Mongo was working fine in my Ubuntu machine, but whenever I access mongo shell, it will display the following warning.

root@abc:~# mongo
MongoDB shell version: 2.4.5
connecting to: test
Server has startup warnings:
Tue Aug 13 03:47:13.764 [initandlisten]
Tue Aug 13 03:47:13.764 [initandlisten] ** WARNING: You are running on a NUMA machine.
Tue Aug 13 03:47:13.764 [initandlisten] **          We suggest launching mongod like this to avoid performance problems:
Tue Aug 13 03:47:13.764 [initandlisten] **              numactl –interleave=all mongod [other options]
Tue Aug 13 03:47:13.764 [initandlisten]

First I checked, whether my hardware is NUMA(Non-Uniform Access Memory) enabled. I got the following output which said the answer is yes, it is NUMA enabled.

root@abcl# dmesg | grep -i numa
[    0.000000] NUMA: Node 1 [mem 0x00000000-0xcfffffff] + [mem 0x100000000-0x82fffffff] -> [mem 0x00000000-0x82fffffff]

I can simply start mongo as said in the warning message, but what I was looking forward was a permanent fix which will let me start/stop mongo using the startup script.

 

Unfortunately, numactl command was not present in the server, so I installed the package as follows.

apt-get install numactl

After that, I did the following.

Added the following line to /etc/sysctl.conf

vm.zone_reclaim_mode = 0

Now, made the following change to the file /etc/init/mongodb.conf

Commented out line 18 which is as follows.

#  if [ “x$ENABLE_MONGODB” = “xyes” ]; then exec start-stop-daemon –start –quiet –chuid mongodb –exec  /usr/bin/mongod — –config /etc/mongodb.conf; fi

Now added the following line.

if [ “x$ENABLE_MONGODB” = “xyes” ]; then exec start-stop-daemon –start –quiet –chuid mongodb –exec  /usr/bin/numactl — –interleave=all /usr/bin/mongod –config  /etc/mongodb.conf; fi

Save and quit the file.

After doing this you need to restart mongodb and check whether mongo shell is accessible without the warning.

 

root@abc# /etc/init.d/mongodb start
Rather than invoking init scripts through /etc/init.d, use the service(8)
utility, e.g. service mongodb start

Since the script you are attempting to invoke has been converted to an
Upstart job, you may also use the start(8) utility, e.g. start mongodb
mongodb start/running, process 21750

Check if mongo is running

 

root@abc# ps aux | grep mongo
mongodb  21750  1.0  0.0 348116 37516 ?        Ssl  04:13   0:00 /usr/bin/mongod –config /etc/mongodb.conf
root     21762  0.0  0.0   9384   920 pts/0    S+   04:13   0:00 grep –color=auto mongo

Try accessing the mongo shell

root@abc# mongo
MongoDB shell version: 2.4.5
connecting to: test
>
bye

 

Success!!!! In case of error, you can check the log file at /var/log/mongodb/mongodb.log

IIS file upload limit issue of 30M

I had wordpress setup for one of my domains in a windows 2008 server with IIS7. All files uploads upto 30M was working fine, but more than that no luck. Then I read that IIS7 has a default upload limit of 30M. I had to do two things to get it working. Details given below.

Click Start -> Internet Information Services Manager

Click on the webserver name to highlight it(in order to make changes globally) or just click on your website name to enable changes for that site alone.

On features view, scroll down to IIS -> Request Filtering.

On the right pane, click on Edit Feature Settings

Look for the field “Maximum Allowed Content Length”. It will be the default value of 30000000

Change the value to 104857600 which is 100M.

Save the changes and restart IIS(usually a restart is not needed)

 

Now try uploading a file which is larger than 30M and see if the upload is successful.

If the upload still fails, check if urlscan is enabled. The configuration file for Urlscan is normally present at C:\Windows\System32\inetsrv\urlscan\urlscan.ini

It might sometimes contain the following.

MaxAllowedContentLength=30000000

Change that also to 104857600, save the file and restart IIS.

Try uploading a bigger file now. If it still fails, check the following.

Open the file C:\Windows\system32\inetsrv\config\applicationhost.config

Locate the <requestLimits>

Check if it contains a variable maxAllowedContentLength. If it is present, either remove it or modify its value to 104857600.

Save the file and try uploading again.

If it still fails, you need to check the logs and find if there is any other file which conflicts with this setting.

sysadminnnn!!!!

computers-sysadmin-sys_admin-technical_support-it-office_work-dbnn30l

Devotion to duty ;)

devotion_to_duty

Finding spamming in qmail

Spamming ???

Qmail is said to be secure and as such there are very less chances for spamming. In case of spamming, you can find out the culprit as said in the following example.

Try running /var/qmail/bin/qmail-qread. The utility on a server gave the following output.

20 Sep 2007 05:29:32 GMT #96945 24355 <spam@domain.com> bouncing
done remote giaygoiqua@test.com
done remote giayvietplaza@test1.com
done remote gig@domain123.com
done remote gilbert.marc@abc.com
done remote gillvector@fptnet.com.net
done remote gimmy.vo@azf.com
remote gin@dom.com

This shows that a lot of messages were sent from the address spam@domain.com and that all of them have bounced. In order to find the message content, to make sure it is spam, do the following.

# cd /var/qmail/queue/mess
# find . -iname 96945 ( 96945 is the message number which you get from the first line pasted above)

If the message content looks suspicious, you can take immediate action against the domain domain.com.

 

Upcp hanging – Bad archive: CPAN-SQLite-0.203.tar.gz

 

 

If you get the error mention in the title, do the following.

ps aux | grep upcp      – will list the upcp processes running

kill -9 pid              – kill that process where pid is the process id listed in the above command output

cpan -i CPAN::SQLite   - install the cpanel sqlite module directly

/scripts/upcp --force  - run upcp again

Hello world!

Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!