Skip to content

Instantly share code, notes, and snippets.

@w00lf
Created January 11, 2017 12:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save w00lf/5770c5808eae4f110bfa05dd8d75a0af to your computer and use it in GitHub Desktop.
Save w00lf/5770c5808eae4f110bfa05dd8d75a0af to your computer and use it in GitHub Desktop.
Mruby nginx redirects with redis
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
FROM centos:latest
MAINTAINER Mikl Taraskin <example@gmail.com>
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
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
# 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";
}
}
}
@StGerman
Copy link

Пара вопросов:

  1. Надо подумать как сохранить данные при перезапуске redis контейнера
  2. Какое время ответа от контейнера, сколько задержка на mruby + сходить в redis?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment