Git Product home page Git Product logo

nginx_config_maker's Introduction

NginxConfigMaker

Generate Nginx conguration using Ruby

Installation

Add this line to your application's Gemfile:

gem 'nginx_config_maker'

And then execute:

$ bundle

Or install it yourself as:

$ gem install nginx_config_maker

Usage

To generate upstream configuration like this:

upstream app_123 {
  server 127.0.0.1:12380;
}

do:

upstream = NginxConfigMaker::Upstream.new(
  name: "app_123",
  host: "127.0.0.1",
  port: "12380",
)
upstream.to_s

To generate server configuration like this:

server {
  listen      [::]:80;
  listen      80;
  server_name app_123;
  location    / {
    proxy_pass  http://$APP;
    proxy_http_version 1.1;
    proxy_set_header Upgrade \$http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header Host \$http_host;
    proxy_set_header X-Forwarded-Proto \$scheme;
    proxy_set_header X-Forwarded-For \$remote_addr;
    proxy_set_header X-Forwarded-Port \$server_port;
    proxy_set_header X-Request-Start \$msec;
  }
  location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }
}

do:

server = NginxConfigMaker::Server.new(
  listen: ["[::]:80", "80"],
  server_name: "app_123",
  location: [
    {
      at: "/",
      proxy: {
        pass: "http://app_123",
        http_version: "1.1",
        set_headers: {
          "Upgrade" => "\$http_upgrade",
          "Connection" => %Q("upgrade"),
          "Host" => "\$http_host",
          "X-Forwarded-Proto" => "\$scheme",
          "X-Forwarded-For" => "\$remote_addr",
          "X-Forwarded-Port" => "\$server_port",
          "X-Request-Start" => "\$msec",
        }
      }
    },
    {
      at: '^~ /assets/',
      gzip_static: 'on',
      expires: 'max',
      add_header: 'Cache-Control public'
    }
  ]
)
server.to_s

Contributing

  1. Fork it ( http://github.com//nginx_config_maker/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.