Installing Nignx as a Service on Windows

Setting up Nginx on Windows is a straightforward endeavor. Unfortunately the information on how to do it end to end is not exactly in one spot, but actually sprinkled throughout the internet. So here we go, let's put it all together.

Installing Nginx

  1. Download the binary from the Nginx website. This is what the website looks like today and the latest version is 1.15.2. nginx download page

  2. Unzip it to a folder of your preference. You might want to unblock the download first though, by right-clicking and selecting properties. On the properties window there's an unblock checkbox. In this case I am going to unzip the download directly on the root. It will look something like this: nginx unzipped folder

You could now start it up as a console application by running nginx.exe, but that's only useful if you only want it to run when you're logged in. We want it to run whenever the computer starts, so let's install it as a windows service.

Setting Nginx Up as a Windows Service

The guidance here is to use one of the many tools out there that let you install an executable as a windows service. There's no magic here. That all it is. We wrap the executable in a service wrapper and install it using one of the open source tools available to us. I'll show you how to do it using NSSM, but just follow the instructions for the particular wrapper tool you end up using.

Installing nssm

  1. Download the NSSM binary from the NSSM website. Like Nginx, that is also a zip file.
  2. Unzip nssm to any folder but unblock it before you do. Again I'm going to unzip it to the root of the drive and use the folder name that is in the zip file. It will look something like this: nssm unzipped folder

Using NSSM to Install Nginx as a Windows service

The last part is to use NSSM to create a windows service that will run the nginx executable. That's simple enough but it must be done from a command window. So open a command window and run the following command:

 nssm install

This will launch the NSSM "helper" and you can now select the nginx.exe file and give the service a name: nssm application window The defaults will work, except that you should set up a user to run the nginx service and not use the system account because it has unrestricted access to the machine. The Log on tab is where you can change that: nssm log on as screen Feel free to explore the rest of the options in NSSM's help pages.

No More Cookies

As of today we no longer use cookies on this site. In the past we used cookies to support some telemetry and visit statistics. As it turns out, I didn't really look at that data and so I've decided to remove both GA and AI tracking scripts.

Enabling SSH Access on the IX4-300D NAS

The IX4-300D NAS device can be configured for SSH access by following these steps:

  1. Log in using the administrator account
  2. Navigate to the Diagnostics screen: http://ix4-300d/manage/diagnostics.html
  3. Select Support Access -> Allow remote access for support
  4. Enter the root password twice and click apply

Now you will be able SSH into the NAS, using the root user, and with the password you entered, prepended by soho.

Running Docker Quickstart Terminal Inside ConEmu

In trying to streamline my workflow I wanted to be able to run the Docker Quickstart Terminal from ConEmu. I've been working in ConEmu for all of my command line activity and it's a way better experience overall. This post describes how to configure ConEmu so that you can get the Docker Quickstart Terminal to run inside of it. I'm going to assume you already installed ConEmu and the Docker Toolbox. This post is written against ConEmu 16.4.16.0 and Docker Toolbox 1.11.1. Let's walk through this process now.

We'll be creating a new task in ConEmu, so open ConEmu and press Win+Alt+T to open the Settings screen. You can also open the screen pressing the green plus sign on the top right of the screen and selecting Setup Tasks from the dropdown options: ConEmu main screen with highlighted button

You should now be at the settings screen, which will look something like this: ConEmu settings screen

Next, click on the plus button just under the list of Predefined tasks. This will add a new task at the bottom of the list, which gets defaulted to GroupXX. On my screen it's Group12: ConEmu settings screen with the add button highlighted

The final step is to configure the task we just added. In my case I am calling it Docker Toolbox but you can call it anything you want. In addition to changing the name, you'll have to add two more pieces of information.

First, we'll set the working directory by adding a task parameter. The task parameter for a default Docker installation wil be:

/dir "C:\Program Files\Docker Toolbox"

If you installed the Docker Toolbox to a different directory, change the above line accordingly.

Second, we need to add a command to the task. The command you want to add is this one:

"C:\Program Files\Git\bin\bash.exe" --login -i "C:\Program Files\Docker Toolbox\start.sh"

This command assumes you are using Git as well, so if you are using a different bash shell, you will have to change this to use a different shell. This is a screenshot of what that looks like once it has been configured. Your screen should look like this unless you've changed some of the installation paths:

ConEmu settings screen with docker config

If your installation is significantly different you can copy the command lines directly from the Docker Quickstart Terminal shortcut. This is what I did and you'll see that the lines above will match the lines on the screen below. To find the shortcut file so that you can copy the commands from it, navigate to this folder:

C:\Users\your-user-folder-name\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Docker

That folder will contain the docker shortcut files. Right click on the Docker Quickstart Terminal shortcut and select properties from the context menu. You should now be at the properties screen:

docker quickstart terminal properties screen

You can now copy the value in the target field and copy it into the ConEmu command field in the ConEmu settings window for you task. Then, copy the value in the Start In field and paste it into the task parameters field in the ConEmu settings window. This last value needs to be prefaced by /dir. See my example above and compare it to the values in my properties window.

Finally, remember to click on save settings. Now you should be able to start a new Docker Toolbox tab.

Installing Docker Toolbox on Windows with Hyper-V Installed

Installing Docker on Windows is a fairly simple and straightforward process. It is very well documented here. However if you have Hyper-V installed as I do, the instructions will not work right out of the box. If you try to start the Docker Quickstart Terminal, you'll get the following error message:

Running pre-create checks...
Error with pre-create check: "Hyper-V is installed. VirtualBox won't boot a 64bits VM when Hyper-V is activated. If it's installed but deactivated, you can use --virtualbox-no-vtx-check to try anyways"
Looks like something went wrong in step ┬┤Checking if machine default exists┬┤

The issue is that when you run the terminal the very first time, the startup script attempts to create the default virtual machine in which the docker containers will run. This step of the process fails if you have Hyper-V installed, even if it is disabled. In my case, I do have it installed but I have a boot option set up to disable it when I am not using it. This post describes how to change the Docker startup script to allow you to create the default virtual machine using the startup script and still keep Hyper-V installed.

Before you start with the installation of Docker, I would suggest disabling Hyper-V. If you don't know how to do this, follow these instructions. Once you have disabled Hyper-V, the first step is to install Docker using the installer for Windows. The installation should run without any issues before you proceed with the next steps.

Once you have installed Docker, we'll modify the startup file to allow it to create the default VM. The file we want to modify is located under C:\Program Files\Docker Toolbox and is called called start.sh. To modify the file you'll have to open the file in an editor running as Administrator. If you don't open an elevated editor, you won't be able to save your changes.

It's now time to edit the file, but before you do so, you may want to save a copy of the original file. Just in case. In your editor, locate the following code snippet:

STEP="Checking if machine $VM exists"
if [ $VMEXISTSCODE -eq 1 ]; then
  "${DOCKERMACHINE}" rm -f "${VM}" &> /dev/null || :
  rm -rf ~/.docker/machine/machines/"${VM}"
  #set proxy variables if they exists
  if [ -n ${HTTPPROXY+x} ]; then
    PROXYENV="$PROXYENV --engine-env HTTPPROXY=$HTTPPROXY"
  fi
  if [ -n ${HTTPSPROXY+x} ]; then
    PROXYENV="$PROXYENV --engine-env HTTPSPROXY=$HTTPSPROXY"
  fi
  if [ -n ${NOPROXY+x} ]; then
    PROXYENV="$PROXYENV --engine-env NOPROXY=$NOPROXY"
  fi
"${DOCKERMACHINE}" create -d virtualbox $PROXYENV "${VM}" fi
The second to last line is where the vm is created:
"${DOCKERMACHINE}" create -d virtualbox $PROXYENV "${VM}"

You will need to modify that line and add the --virtualbox-no-vtx-check switch to. The end result is that the line will look like this:

"${DOCKERMACHINE}" create -d virtualbox --virtualbox-no-vtx-check $PROXYENV "${VM}"

Save your changes and now you should be able to run the quickstart terminal without any issues.