That's a very long RUN command - it might be better to write that as a shell script which you ADD and then RUN. That has advantages such as using a shell-syntax-aware editor or being able to run shellcheck or other tools on it. In any case, I recommend set -u to catch misspelt variable names.
Quite a few commands in the script are wget commands. It might be better to use Dockerfile's ADD for these rather than having the shell fetch them. Downside of that is that we end up with bigger layers, so consider what size impact they have.
Repeated use of $(cd .. && pwd) suggests that a variable could be used there - or, since you know the working directory, just use absolute pathnames.
Did you check whether relative paths work (i.e. just ..)? Or perhaps (with Bash as interpreter) we could make a relative path using ~+/...
Also related to directory changing - we could use Make's -C option to reduce the number of cd invocations, and make it easier for the reader to keep track of working directory.
For example,
cd luajit2-${LUAJIT_VERSION} && make install && cd ..
becomes
make -C luajit2-${LUAJIT_VERSION} install
If there were other temporary changes of directory, we could consider using a subshell to isolate the directory change:
(cd workdir && command)
It's good that you have rm -rf /tmp/build/nginx after using the sources to build - that can make a big difference to the size of the layer.