Recently I ran into an issue when trying to set Nginx up in New Relic because the repository I used to
apt-get install nginx from wasn't actually the developer's repository. Little did I know that by default, Ubuntu doesn't pull from Nginx's repository when you
apt-get so the code I was pulling, while functional, was missing the standard configuration needed to get proper support from Nginx for their New Relic plugin.
Here's how I was able to fix it.
Add the Repos
First, you'll want to edit your
/etc/apt/sources.list file to include the official Nginx repos. This file is where
apt-get update pulls changes made so when you run
upgrade it detects the changes and prompts you to proceed with the latest changes. The two repos are:
deb http://nginx.org/packages/ubuntu/ trusty nginx deb-src http://nginx.org/packages/ubuntu/ trusty nginx
It's important to note that you'll want to substitute out
trusty for your particular Ubuntu installation, otherwise you might wind up pulling an incompatible version of Nginx for your distro version. You can follow the following naming conventions here:
- Ubuntu 10.04 LTS - lucid
- Ubuntu 10.10 - maverick
- Ubuntu 11.04 - natty
- Ubuntu 11.10 - oneiric
- Ubuntu 12.04 LTS - precise
- Ubuntu 12.10 - quantal
- Ubuntu 13.04 - raring
- Ubuntu 13.10 - saucy
- Ubuntu 14.04 LTS - trusty
You can ensure that you're pulling from the correct repo when you run
apt-get update and see the following lines in the output:
Ign http://nginx.org trusty/nginx Translation-en_US Ign http://nginx.org trusty/nginx Translation-en
After these lines are added, you'll be pretty well set to update but before you
apt-get with your new repos, back up your existing /etc/nginx/ directory. I cannot stress this enough. You can seriously bork your existing, working installation of Nginx by upgrading, depending on how old your existing version is compared to the one you're pulling from the repository. Third-party repos for Nginx can cause you to pull an out-of-date version. When running
apt-get upgrade I found that my current install was running version 1.4.1 compared to the latest release of 1.6.0. Harsh.
The reason I say that you can bork your current install is from personal experience. Initially when I ran
upgrade, it detected there was an updated version I needed to pull, however, it wouldn't install it because of some obscure conflict in
/var/cache/apt/archives saying it couldn't overwrite the cache for version 1.4.1. However, after the conflict was resolved, it still wouldn't install, saying that Nginx was already installed.
The trick to solve this issue (for me) was to delete all references to Nginx, run
apt-get remove nginx and then
apt-get install nginx. The reason I had to remove it first was because despite running
rm -r /etc/nginx, Ubuntu still thinks Nginx is installed until the
remove command is run. Nothing like a clean nuke to fix any residual issues.
After the install was successfully run and file conflicts were resolved with config files, I was finally able to get Nginx up and running again. To ensure that the process would still start upon install, I did a few reboots of the VPS to ensure it would fire up properly. Altogether, it probably took me about an hour - most of the time was spent figuring out the apt cache conflicts and how to resolve it. YMMV.