Skip to content

Instantly share code, notes, and snippets.

@w00lf
Created January 11, 2017 12:27
Show Gist options
  • Select an option

  • Save w00lf/5770c5808eae4f110bfa05dd8d75a0af to your computer and use it in GitHub Desktop.

Select an option

Save w00lf/5770c5808eae4f110bfa05dd8d75a0af to your computer and use it in GitHub Desktop.

Revisions

  1. w00lf revised this gist Jan 11, 2017. 1 changed file with 13 additions and 0 deletions.
    13 changes: 13 additions & 0 deletions docker-compose.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    version: '2'
    services:
    redis:
    image: redis
    nginx:
    build: .
    command: tail -f /var/log/nginx/access.log
    environment:
    - REDIS_URL=redis
    ports:
    - "3000:3000"
    depends_on:
    - redis
  2. w00lf created this gist Jan 11, 2017.
    9 changes: 9 additions & 0 deletions Dockerfile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    FROM centos:latest
    MAINTAINER Mikl Taraskin <[email protected]>
    ADD nginx-build-rpm /tmp/nginx-build-rpm
    WORKDIR /tmp/nginx-build-rpm
    RUN rpm -Uvh nginx-build.rpm
    RUN yum install -y redis
    RUN mkdir -p /etc/nginx/include.d/rewrites/
    ADD example.rb /etc/nginx/include.d/rewrites/example.rb
    ADD nginx.conf /etc/nginx/nginx.conf
    11 changes: 11 additions & 0 deletions example.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    client = Redis.new('redis', 6379, 2) # Connect to the server ENV['REDIS_URL']
    client.select 0

    r = Nginx::Request.new
    Nginx.errlogger Nginx::LOG_ERR, "request uri: #{r.uri}"

    if matched_redirect = client.get(r.uri)
    matched_redirect
    else
    r.uri
    end
    16 changes: 16 additions & 0 deletions nginx.conf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    # Work around problem 'no "events" section in configuration'
    events { }

    http {
    server {
    listen 3000;

    location / {
    mruby_set $redirect_candidate "/etc/nginx/include.d/rewrites/example.rb";
    if ($redirect_candidate != $request_uri) {
    rewrite ^(.*)$ $redirect_candidate permanent;
    }
    return 200 "hello world";
    }
    }
    }