Monday, September 19, 2016

NGINX 1.4.6 upgrade on AWS EC2

I've been working with NGINX a lot more lately and still love it.

The info:
Using AWS EC2 with Ubuntu 14.04 (trusty)
NGINX 1.4.6 as a web server

During a PCI compliance scan, it was found the the server I was working on was running NGINX 1.4.6, a version released on 2014-03-04, nearly 2 and a half years old (at this writing).

This is the default version installed with the AWS packages for Ubuntu anyway, but I'm not sure about other packages.

On the DEV machine I was using, I tried to do the basic update:
sudo apt-get install nginx

The resulting version of NGINX was still 1.4.6, so I figured it was the repo being used.


FIRST STEP: Make sure you backup your config files!!! To some place other than /etc/nginx/, like perhaps your home dir. When I performed my install, all the files in /etc/nginx/sites-available were deleted.


I found this nice article on nginx's website: https://www.nginx.com/resources/admin-guide/installing-nginx-open-source/#prebuilt_ubuntu
I followed the above section on Ubuntu and everything went great.


After the upgrade was complete, I was running 1.11.4. Great! But now I had to configure my website.
The files in /etc/nginx/sites-available  were gone, so I copied my backup to that directory.

Then in /etc/nginx/nginx.conf
  1. set user to www-data
  2. Add the line if you are still using sites-available:
    1. include /etc/nginx/sites-enabled/*;

In the directory /etc/nginx/conf.d, rename default.conf to something else.

Restart NGINX:
sudo service nginx restart




Tuesday, June 7, 2016

Drupal Rules - Sending to Multiple Emails

This one took me awhile, with a lot of interesting testing.

I had a Rule setup to email a user when a node went to a certain Workflow state. Easy enough.

myemail@example.com  works just fine!


To add a second email? Difficult. That's the part where you actually need to read the description in the TO section of the Action:
"The formatting of this string must comply with RFC 2822."

What's RFC 2822? No clue really, until I did some research. Read this if you want to know the whole RFC. https://tools.ietf.org/html/rfc2822#page-15

Based on Page 15 and looking at an email I had received through my GMail, I decided to try using the angle brackets. Here's what I got:

<myemail@example.com>, <jarod@example.com>

I re-ran the rule and received the email I was expecting. Jeepers!


Monday, May 23, 2016

Webmin on CentOS 7

Here's a great resource page for installing Webmin:
If you can't access the Webmin login screen when you are done, (https://[server-ip]:10000) then you may need to review your firewall rules. 
For IPtables, this worked for me: http://www.webmin.com/firewall.html

Thursday, April 21, 2016

Drupal - Field Collection - Appending/Inserting an Entity

Kudos for this solution goes to Drupaler Justin Fraser :
Slightly changed description to fit more of my append/insert issue.


I had an issue where I was trying to append new field collection entity to the 'user' Field Collection and doing so would delete any existing items. The solution was to directly load the user entity and not depend on the global $user as that one doesn't have the field collection information.
$thisUser = entity_load('user', array($user->uid));
$thisUser = $thisUser[$user->uid]; //make thisUser the user object, not an array of user objects

$newFieldCollectionItem = array();
$newFieldCollectionItem['field_name'] = 'field_download';
$newFieldCollectionItem['field_download_filename'][LANGUAGE_NONE][0]['value'] = $src;
$newFieldCollectionItem['field_download_date'][LANGUAGE_NONE][0]['value'] = time();

$newFieldCollection = entity_create('field_collection_item', $newFieldCollectionItem);
$newFieldCollection->setHostEntity('user', $thisUser);
$newFieldCollection->save();

Line 2 $thisUser[$user->uid] is what made it work for me.

The rest of the code had been the exact same, but adding line 2 is what did it for me!!!

Wednesday, February 17, 2016

IP Range for where you are.


Synopsis....

I needed to enable a range of IP's for use in an AWS Security Group so that other developers could access a test website I was working on. Here's how I found the smallest range, rather than opening it the whole world. NOTE: There is a small security issue with this method, it is described below.

All IP's pointing to me have been obfuscated...your eyes aren't going bad. :)

Step 1 - Find your IP

There's lots of ways to do this, but the quick simple way I use is simply going to

https://myip.ms/

And there's your IP!



Step 2 - Find Your IP Range

Now you know your IP. Now click on the WHOIS? icon and it takes you to the next page which shows you everything known about that IP. Who owns it, the IP range that is owned by them, etc.

Here's my general IP range:
X.X.128.0 - X.X.255.255    (32,768 ip)

So I want to figure out the short form of that IP Range.

Scroll down (or search) for CIDR. This is the value you want to use. The whole thing. For example, X.X.128.0/17 (it may be different based on the IP Range from above).



This CIDR is the value I used in the AWS console to denote my range of IP's.

Now the security hole here is that anyone in this set of 32,768 IP's can access my special website (on a specific port) that I setup with this particular rule. I'm ok with this small, if not virtually non-existent hole for my TEST website. Risk vs. Reward. I'll be sure to lock down the production site though.

More information on CIDR and what it means:
https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing