Code Monkey home page Code Monkey logo

boxcars's Introduction

Easy-to-configure Static Web/Reverse Proxy Server in Go.

Install

$ go get github.com/azer/boxcars/boxcars

Works with Go v1.1+

Usage

Create a configuration file (it'll be auto-loading changes once you start) like the below example;

{
  "foo.com": "/home/you/sites/foo.com",
  "*.bar.net": "localhost:8080",
  "qux.org": {
    "/static": "/home/you/qux.org/static",
    "/favicon.ico": "/home/you/qux.org/static/favicon.ico",
    "/": "localhost:3000"
  }
}

And start the server:

$ boxcars config.json

To specify the port:

$ boxcars -port=8001 config.json

Always enable secure mode when running as sudo:

$ sudo boxcars -port=80 -secure config.json

You can change the configuration anytime during boxcars running. It'll be watching your file and reloading it only if it parses with no error.

Configuration Examples

I use below configuration for a static single-page app that connects to an HTTP API:

{
  "singlepage.com": {
    "/api": "localhost:1337",
    "*": "sites/singlepage.com"
  }
}

To catch any domain:

{
  "foo.com": "localhost:1234",
  "*": "/home/you/404.html"
}

To set a custom 404 page for a static server:

{
  "foo.com": {
    "/": "/home/you/sites/foo.com",
    "*": "/home/you/404.html"
  }
}

Security

Once you enable -secure, boxcars switches from root user to a basic user after starting the server on specified port.

$ sudo boxcars -port=80 -secure example.json

UID and GID is set to 1000 by default. Use -uid and -gid parameters to specify your own in case you need.

Logging

Boxcars uses debug for logging. To enable logging for specific modules:

$ DEBUG=server,sites boxcars config.json

To see how boxcars setup the HTTP handlers for your configuration;

$ DEBUG=handlers-of,sites boxcars config.json

To enable very verbose mode (not recommended):

$ DEBUG=* boxcars config.json

To silentize:

$ DEBUG=. boxcars config.json

It'll be outputting to stderr.

Benchmarks

Troubleshooting

The "Too Many Open Files" Error

Boxcars creates a lot of files on /proc/$pid/fd. In case you see boxcars crashing, you can see how many files are open by;

$ sudo ls -l /proc/`pgrep boxcars`/fd | wc -l

To find out your personal limit:

$ ulimit -n

To change it:

$ ulimit -n 64000

You can change soft - hard limits by editing /etc/security/limits.conf.

TODO

  • Add -daemon option.

boxcars's People

Contributors

danclien avatar justinazoff avatar crosbymichael avatar

Watchers

Marcelle von Wendland avatar James Cloos avatar

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.