1
votes

Is it possible to run multiple sinatra applications on my workstation for development?

OSX El Capitan, nginx, Passenger, Sinatra

I have nginx and passenger installed. It works in standalone mode. But I use this type of software to serve an in-house "home page" which I reference a lot, and I have multiple projects at different stages that I am developing. So having a single standalone is highly restrictive. I would like to serve one local 'virtual host' application with another one in a subdirectory. Namely, '/' and '/motherlode_ruby', and other nested apps in the future.

I'm under the impression that Passenger can serve multiple instances at the same time. Unfortunately Phusion hasn't explained this type of nginx multiple mode setup too well, as they focus on standalone on nginx. So here is my setup:

nginx.conf:

    http {
            index                                   index.html;
            access_log                          /usr/local/var/log/access.log;

            passenger_root /usr/local/opt/passenger/libexec/src/ruby_supportlib/phusion_passenger/locations.ini;
            passenger_ruby /Users/rich/.rvm/gems/ruby-2.2.3/wrappers/ruby;

            server {
                listen                      8080 default_server;
                server_name                 hq.local;
                include                         /usr/local/etc/nginx/mime.types;
                access_log                  /usr/local/var/log/access_HQ5.log;
                error_log                   /usr/local/var/log/error_HQ5.log  debug;
                error_page  404     /404.html;
                root                            /Library/WebServer/Documents/HQ5/public;    
                passenger_enabled on;
                passenger_base_uri  /;
                passenger_base_uri  /motherlode_ruby;
                passenger_env_var DATABASE_USERNAME myusername;
                passenger_env_var DATABASE_PASSWORD mypassword;

                location / {
                    autoindex off;
                        # try_files             $uri $uri/ /index.html?$query_string;
                }

                location = /favicon.ico { access_log off; log_not_found off; }
                location = /robots.txt { access_log off; log_not_found off; }

                sendfile                        off;
            }
            # other servers currently commented out
    }

This is essentially what I'm looking for:

    hq.local:
        app.rb
        app1:
            app.rb                                                      
            Gemfile
            methods.rb
            public:
                main.css
            ref.rb
            views:
                index.erb
                result.erb
        app2:
            app.rb
            Gemfile
            methods.rb
            public:
                main.css
            ref.rb
            views:
                index.erb
                result.erb
        Gemfile
        methods.rb
        public:
            main.css
        ref.rb
        views:
            index.erb
            result.erb

Currently under standalone on 0.0.0.0:3000 the hq.local serves just fine, but I have to serve motherlode_ruby from that top project. Is there a way I can serve that separately, as well as other local vhosts? Sinatra file in hq.local:

    require 'sinatra/base'

    class MyApp < Sinatra::Base
        get "/" do
            "OK, yer in HQ5 top"
        end

        get "/motherlode_ruby" do
            "OK, yer in HQ5/motherlode_ruby"
        end

        get "/alpha" do
            "OK, yer in HQ5/alpha"
        end

        get "/bravo" do
            "OK, yer in HQ5/bravo"
        end
    end
1

1 Answers

0
votes

Make sure your passenger_root is set properly using the result of "passenger-config --root". Then everything gets auto-sensed.