Skip to content

Instantly share code, notes, and snippets.

@jmervine
Last active November 6, 2019 20:26
Show Gist options
  • Select an option

  • Save jmervine/5407622 to your computer and use it in GitHub Desktop.

Select an option

Save jmervine/5407622 to your computer and use it in GitHub Desktop.

Revisions

  1. jmervine revised this gist Apr 23, 2013. 1 changed file with 1 addition and 56 deletions.
    57 changes: 1 addition & 56 deletions installing_nginx_with_lua.mdown
    Original file line number Diff line number Diff line change
    @@ -1,56 +1 @@
    # Installing Nginx with Lua module

    [Download the script.](https://gist.github.com/jmervine/5407622/raw/nginx_w_lua.bash)

    Or run the following command:

    bash < <(curl -s https://gist.github.com/jmervine/5407622/raw/nginx_w_lua.bash)

    ### What's it do?

    * Download LuaJIT 2.0.1
    * Install LuaJIT 2.0.1
    * Link `luajit` to `lua`
    * Download NDK
    * Download lua-nginx-module
    * Download Nginx 1.2.8
    * `configure` Nginx with lua-nginx-module
    * Install Nginx

    Binary Results:

    * `/opt/nginx/sbin/nginx`
    * `/usr/local/bin/lua`
    * `/usr/local/bin/luajit`

    Lib Results:

    * `/usr/local/lib/*lua*`

    Include Results:

    * `/usr/local/include/luajit-2.0/*`

    ### Starting Nginx

    $ LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH /opt/nginx/sbin/nginx -c /path/to/nginx.conf

    ### Update existing Nginx init:

    Stop Nginx: `sudo /etc/init.d/nginx stop`

    Patch [`/etc/init.d/nginx`](https://gist.github.com/jmervine/5407622#file-nginx-init-sh) like so:

    13,14c13,18
    < PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
    < DAEMON=/usr/sbin/nginx
    ---
    > export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
    >
    > # ensure default configuration location
    > test "$DAEMON_OPTS" || DAEMON_OPTS="-c /etc/nginx/nginx.conf"
    > PATH=/opt/nginx/sbin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
    > DAEMON=/opt/nginx/sbin/nginx`


    > Note: the above may not be the best way, but it's what I had to do to get it to work and I didn't have a ton of time to mess with it.
    ### See: [http://www.rubyops.net/nginx-with-lua-module](http://www.rubyops.net/nginx-with-lua-module)
  2. jmervine revised this gist Apr 23, 2013. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions nginx_w_lua.bash
    Original file line number Diff line number Diff line change
    @@ -12,8 +12,6 @@ if ! test -d /usr/local/include/luajit-2.0; then
    cd LuaJIT-2.0.1
    make
    sudo make install

    test -x /usr/local/bin/lua || sudo ln -s /usr/local/bin/luajit /usr/local/bin/lua
    else
    echo "Skipping LuaJIT-2.0.1, as it's already installed."
    fi
  3. jmervine revised this gist Apr 18, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion installing_nginx_with_lua.mdown
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    # Installing Nginx with Lua module

    [Download the script.](https://gist.github.com/jmervine/5407622#file-nginx_w_lua-bash)
    [Download the script.](https://gist.github.com/jmervine/5407622/raw/nginx_w_lua.bash)

    Or run the following command:

  4. jmervine revised this gist Apr 18, 2013. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions installing_nginx_with_lua.mdown
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,13 @@
    # Installing Nginx with Lua module

    [Download the script.](https://gist.github.com/jmervine/5407622#file-nginx_w_lua-bash)

    Or run the following command:

    bash < <(curl -s https://gist.github.com/jmervine/5407622/raw/nginx_w_lua.bash)

    ### What's it do?

    * Download LuaJIT 2.0.1
    * Install LuaJIT 2.0.1
    * Link `luajit` to `lua`
  5. jmervine revised this gist Apr 18, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion installing_nginx_with_lua.mdown
    Original file line number Diff line number Diff line change
    @@ -31,7 +31,7 @@ Include Results:

    Stop Nginx: `sudo /etc/init.d/nginx stop`

    Patch `/etc/init.d/nginx` like so:
    Patch [`/etc/init.d/nginx`](https://gist.github.com/jmervine/5407622#file-nginx-init-sh) like so:

    13,14c13,18
    < PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  6. jmervine revised this gist Apr 18, 2013. 1 changed file with 100 additions and 0 deletions.
    100 changes: 100 additions & 0 deletions nginx.init.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,100 @@
    #!/bin/sh

    ### BEGIN INIT INFO
    # Provides: nginx
    # Required-Start: $local_fs $remote_fs $network $syslog
    # Required-Stop: $local_fs $remote_fs $network $syslog
    # Default-Start: 2 3 4 5
    # Default-Stop: 0 1 6
    # Short-Description: starts the nginx web server
    # Description: starts nginx using start-stop-daemon
    ### END INIT INFO

    export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH

    # ensure default configuration location
    test "$DAEMON_OPTS" || DAEMON_OPTS="-c /etc/nginx/nginx.conf"
    PATH=/opt/nginx/sbin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
    DAEMON=/opt/nginx/sbin/nginx
    NAME=nginx
    DESC=nginx

    # Include nginx defaults if available
    if [ -f /etc/default/nginx ]; then
    . /etc/default/nginx
    fi

    test -x $DAEMON || exit 0

    set -e

    . /lib/lsb/init-functions

    test_nginx_config() {
    if $DAEMON -t $DAEMON_OPTS >/dev/null 2>&1; then
    return 0
    else
    $DAEMON -t $DAEMON_OPTS
    return $?
    fi
    }

    case "$1" in
    start)
    echo -n "Starting $DESC: "
    test_nginx_config
    # Check if the ULIMIT is set in /etc/default/nginx
    if [ -n "$ULIMIT" ]; then
    # Set the ulimits
    ulimit $ULIMIT
    fi
    start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \
    --exec $DAEMON -- $DAEMON_OPTS || true
    echo "$NAME."
    ;;

    stop)
    echo -n "Stopping $DESC: "
    start-stop-daemon --stop --quiet --pidfile /var/run/$NAME.pid \
    --exec $DAEMON || true
    echo "$NAME."
    ;;

    restart|force-reload)
    echo -n "Restarting $DESC: "
    start-stop-daemon --stop --quiet --pidfile \
    /var/run/$NAME.pid --exec $DAEMON || true
    sleep 1
    test_nginx_config
    start-stop-daemon --start --quiet --pidfile \
    /var/run/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS || true
    echo "$NAME."
    ;;

    reload)
    echo -n "Reloading $DESC configuration: "
    test_nginx_config
    start-stop-daemon --stop --signal HUP --quiet --pidfile /var/run/$NAME.pid \
    --exec $DAEMON || true
    echo "$NAME."
    ;;

    configtest|testconfig)
    echo -n "Testing $DESC configuration: "
    if test_nginx_config; then
    echo "$NAME."
    else
    exit $?
    fi
    ;;

    status)
    status_of_proc -p /var/run/$NAME.pid "$DAEMON" nginx && exit 0 || exit $?
    ;;
    *)
    echo "Usage: $NAME {start|stop|restart|reload|force-reload|status|configtest}" >&2
    exit 1
    ;;
    esac

    exit 0
  7. jmervine revised this gist Apr 17, 2013. 1 changed file with 13 additions and 13 deletions.
    26 changes: 13 additions & 13 deletions installing_nginx_with_lua.mdown
    Original file line number Diff line number Diff line change
    @@ -33,16 +33,16 @@ Stop Nginx: `sudo /etc/init.d/nginx stop`

    Patch `/etc/init.d/nginx` like so:

    `
    13,14c13,18
    < PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
    < DAEMON=/usr/sbin/nginx
    ---
    > export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
    >
    > # ensure default configuration location
    > test "$DAEMON_OPTS" || DAEMON_OPTS="-c /etc/nginx/nginx.conf"
    > PATH=/opt/nginx/sbin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
    > DAEMON=/opt/nginx/sbin/nginx`

    13,14c13,18
    < PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
    < DAEMON=/usr/sbin/nginx
    ---
    > export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
    >
    > # ensure default configuration location
    > test "$DAEMON_OPTS" || DAEMON_OPTS="-c /etc/nginx/nginx.conf"
    > PATH=/opt/nginx/sbin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
    > DAEMON=/opt/nginx/sbin/nginx`


    > Note: the above may not be the best way, but it's what I had to do to get it to work and I didn't have a ton of time to mess with it.
  8. jmervine revised this gist Apr 17, 2013. 1 changed file with 12 additions and 7 deletions.
    19 changes: 12 additions & 7 deletions installing_nginx_with_lua.mdown
    Original file line number Diff line number Diff line change
    @@ -33,11 +33,16 @@ Stop Nginx: `sudo /etc/init.d/nginx stop`

    Patch `/etc/init.d/nginx` like so:

    13,15c13,14
    < export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
    < PATH=/opt/nginx/sbin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
    < DAEMON=/opt/nginx/sbin/nginx
    ---
    > PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
    > DAEMON=/usr/sbin/nginx
    `
    13,14c13,18
    < PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
    < DAEMON=/usr/sbin/nginx
    ---
    > export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
    >
    > # ensure default configuration location
    > test "$DAEMON_OPTS" || DAEMON_OPTS="-c /etc/nginx/nginx.conf"
    > PATH=/opt/nginx/sbin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
    > DAEMON=/opt/nginx/sbin/nginx`

  9. jmervine revised this gist Apr 17, 2013. 1 changed file with 13 additions and 6 deletions.
    19 changes: 13 additions & 6 deletions installing_nginx_with_lua.mdown
    Original file line number Diff line number Diff line change
    @@ -23,14 +23,21 @@ Include Results:

    * `/usr/local/include/luajit-2.0/*`

    ### Starting Nginx

    $ LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH /opt/nginx/sbin/nginx -c /path/to/nginx.conf

    ### Update existing Nginx init:

    Stop Nginx: `sudo /etc/init.d/nginx stop`

    Patch `/etc/init.d/nginx` like so:

    13,14c13,14
    < PATH=/opt/nginx/sbin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
    < DAEMON=/opt/nginx/sbin/nginx
    ---
    > PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
    > DAEMON=/usr/sbin/nginx
    13,15c13,14
    < export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
    < PATH=/opt/nginx/sbin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
    < DAEMON=/opt/nginx/sbin/nginx
    ---
    > PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
    > DAEMON=/usr/sbin/nginx

  10. jmervine revised this gist Apr 17, 2013. 1 changed file with 13 additions and 1 deletion.
    14 changes: 13 additions & 1 deletion installing_nginx_with_lua.mdown
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    Installing Nginx with Lua module:
    # Installing Nginx with Lua module

    * Download LuaJIT 2.0.1
    * Install LuaJIT 2.0.1
    @@ -22,3 +22,15 @@ Lib Results:
    Include Results:

    * `/usr/local/include/luajit-2.0/*`


    ### Update existing Nginx init:

    Patch `/etc/init.d/nginx` like so:

    13,14c13,14
    < PATH=/opt/nginx/sbin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
    < DAEMON=/opt/nginx/sbin/nginx
    ---
    > PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
    > DAEMON=/usr/sbin/nginx
  11. jmervine revised this gist Apr 17, 2013. 1 changed file with 23 additions and 0 deletions.
    23 changes: 23 additions & 0 deletions installing_nginx_with_lua.mdown
    Original file line number Diff line number Diff line change
    @@ -1 +1,24 @@
    Installing Nginx with Lua module:

    * Download LuaJIT 2.0.1
    * Install LuaJIT 2.0.1
    * Link `luajit` to `lua`
    * Download NDK
    * Download lua-nginx-module
    * Download Nginx 1.2.8
    * `configure` Nginx with lua-nginx-module
    * Install Nginx

    Binary Results:

    * `/opt/nginx/sbin/nginx`
    * `/usr/local/bin/lua`
    * `/usr/local/bin/luajit`

    Lib Results:

    * `/usr/local/lib/*lua*`

    Include Results:

    * `/usr/local/include/luajit-2.0/*`
  12. jmervine revised this gist Apr 17, 2013. 2 changed files with 2 additions and 51 deletions.
    50 changes: 0 additions & 50 deletions installing_nginx_with_lua.mdown
    Original file line number Diff line number Diff line change
    @@ -1,51 +1 @@
    Installing Nginx with Lua module:

    #!/usr/bin/bash
    cd /tmp

    if ! test -d /usr/local/include/luajit-2.0; then
    echo "Installing LuaJIT-2.0.1."
    wget "http://luajit.org/download/LuaJIT-2.0.1.tar.gz"
    tar -xzvf LuaJIT-2.0.1.tar.gz
    cd LuaJIT-2.0.1
    make
    sudo make install

    test -x /usr/local/bin/lua || sudo ln -s /usr/local/bin/luajit /usr/local/bin/lua
    else
    echo "Skipping LuaJIT-2.0.1, as it's already installed."
    fi

    mkdir ngx_devel_kit
    cd ngx_devel_kit
    wget "https://github.com/simpl/ngx_devel_kit/archive/v0.2.18.tar.gz"
    tar -xzvf v0.2.18.tar.gz

    NGX_DEV="/tmp/ngx_devel_kit/ngx_devel_kit-0.2.18"

    cd /tmp
    mkdir lua-nginx-module
    cd lua-nginx-module
    wget "https://github.com/chaoslawful/lua-nginx-module/archive/v0.7.21.tar.gz"
    tar -xzvf v0.7.21.tar.gz

    LUA_MOD="/tmp/lua-nginx-module/lua-nginx-module-0.7.21"

    wget 'http://nginx.org/download/nginx-1.2.8.tar.gz'
    tar -xzvf nginx-1.2.8.tar.gz
    cd ./nginx-1.2.8

    export LUAJIT_LIB=/usr/local/lib
    export LUAJIT_INC=/usr/local/include/luajit-2.0

    ./configure --prefix=/opt/nginx \
    --add-module=$NGX_DEV \
    --add-module=$LUA_MOD

    make -j2
    make install

    unset LUAJIT_LIB
    unset LUAJIT_INC


    3 changes: 2 additions & 1 deletion nginx_w_lua.bash
    Original file line number Diff line number Diff line change
    @@ -33,6 +33,7 @@ tar -xzvf v0.7.21.tar.gz

    LUA_MOD="/tmp/lua-nginx-module/lua-nginx-module-0.7.21"

    cd /tmp
    wget 'http://nginx.org/download/nginx-1.2.8.tar.gz'
    tar -xzvf nginx-1.2.8.tar.gz
    cd ./nginx-1.2.8
    @@ -45,7 +46,7 @@ export LUAJIT_INC=/usr/local/include/luajit-2.0
    --add-module=$LUA_MOD

    make -j2
    make install
    sudo make install

    unset LUAJIT_LIB
    unset LUAJIT_INC
  13. jmervine revised this gist Apr 17, 2013. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions nginx_w_lua.bash
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,8 @@
    #!/usr/bin/bash
    #
    # bash < <(curl -s https://gist.github.com/jmervine/5407622/raw/nginx_w_lua.bash)

    set -x
    cd /tmp

    if ! test -d /usr/local/include/luajit-2.0; then
  14. jmervine revised this gist Apr 17, 2013. 1 changed file with 47 additions and 0 deletions.
    47 changes: 47 additions & 0 deletions nginx_w_lua.bash
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,47 @@
    #!/usr/bin/bash
    cd /tmp

    if ! test -d /usr/local/include/luajit-2.0; then
    echo "Installing LuaJIT-2.0.1."
    wget "http://luajit.org/download/LuaJIT-2.0.1.tar.gz"
    tar -xzvf LuaJIT-2.0.1.tar.gz
    cd LuaJIT-2.0.1
    make
    sudo make install

    test -x /usr/local/bin/lua || sudo ln -s /usr/local/bin/luajit /usr/local/bin/lua
    else
    echo "Skipping LuaJIT-2.0.1, as it's already installed."
    fi

    mkdir ngx_devel_kit
    cd ngx_devel_kit
    wget "https://github.com/simpl/ngx_devel_kit/archive/v0.2.18.tar.gz"
    tar -xzvf v0.2.18.tar.gz

    NGX_DEV="/tmp/ngx_devel_kit/ngx_devel_kit-0.2.18"

    cd /tmp
    mkdir lua-nginx-module
    cd lua-nginx-module
    wget "https://github.com/chaoslawful/lua-nginx-module/archive/v0.7.21.tar.gz"
    tar -xzvf v0.7.21.tar.gz

    LUA_MOD="/tmp/lua-nginx-module/lua-nginx-module-0.7.21"

    wget 'http://nginx.org/download/nginx-1.2.8.tar.gz'
    tar -xzvf nginx-1.2.8.tar.gz
    cd ./nginx-1.2.8

    export LUAJIT_LIB=/usr/local/lib
    export LUAJIT_INC=/usr/local/include/luajit-2.0

    ./configure --prefix=/opt/nginx \
    --add-module=$NGX_DEV \
    --add-module=$LUA_MOD

    make -j2
    make install

    unset LUAJIT_LIB
    unset LUAJIT_INC
  15. jmervine created this gist Apr 17, 2013.
    51 changes: 51 additions & 0 deletions installing_nginx_with_lua.mdown
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,51 @@
    Installing Nginx with Lua module:

    #!/usr/bin/bash
    cd /tmp

    if ! test -d /usr/local/include/luajit-2.0; then
    echo "Installing LuaJIT-2.0.1."
    wget "http://luajit.org/download/LuaJIT-2.0.1.tar.gz"
    tar -xzvf LuaJIT-2.0.1.tar.gz
    cd LuaJIT-2.0.1
    make
    sudo make install

    test -x /usr/local/bin/lua || sudo ln -s /usr/local/bin/luajit /usr/local/bin/lua
    else
    echo "Skipping LuaJIT-2.0.1, as it's already installed."
    fi

    mkdir ngx_devel_kit
    cd ngx_devel_kit
    wget "https://github.com/simpl/ngx_devel_kit/archive/v0.2.18.tar.gz"
    tar -xzvf v0.2.18.tar.gz

    NGX_DEV="/tmp/ngx_devel_kit/ngx_devel_kit-0.2.18"

    cd /tmp
    mkdir lua-nginx-module
    cd lua-nginx-module
    wget "https://github.com/chaoslawful/lua-nginx-module/archive/v0.7.21.tar.gz"
    tar -xzvf v0.7.21.tar.gz

    LUA_MOD="/tmp/lua-nginx-module/lua-nginx-module-0.7.21"

    wget 'http://nginx.org/download/nginx-1.2.8.tar.gz'
    tar -xzvf nginx-1.2.8.tar.gz
    cd ./nginx-1.2.8

    export LUAJIT_LIB=/usr/local/lib
    export LUAJIT_INC=/usr/local/include/luajit-2.0

    ./configure --prefix=/opt/nginx \
    --add-module=$NGX_DEV \
    --add-module=$LUA_MOD

    make -j2
    make install

    unset LUAJIT_LIB
    unset LUAJIT_INC