6. Controlling Web Server
Nekonote Framework provides CLI tool for controlling the web server.
Starting Web Server
As mentioned earlier, you can use nekonote
command after installing Nekonote Framework.
Not found nekonote
command? Please run it with bundle exec
or run rbenv rehash
when using rbenv.
on terminal
nekonote new app my_project
cd my_project
bundle
# launch the web server
NEKONOTE_ENV=development nekonote server start
After running the above command, the web server will launch on your machine.
When daemonize
is set false
, you must hit ctrl + C
to stop the web server.
The configuration
It’s possible to change the listening port or document root or more preferences for the web server through the configuration file.
The path to configuration file is preference/your_environment/server/puma.rb
. You can find it by running nekonote server conf
.
As you may know, the web server that launched by nekonote server start
is Puma web server.
Puma is fast web server for Ruby and it supports Rack application.
The way to configure Puma is detailed on Puma’s reference manual. Please take a look it for getting more details.
Preference Examples
I’ll show you some examples.
Changing the port to listen to 80
preference/your_environment/server/puma.rb
# host address to bind
_host = '0.0.0.0'
# listen port
_port = '80'
bind "tcp://#{_host}:#{_port}"
_host
is not allowed IP address nor FQDN. __host
is a bind address.
Changing the web server to work on foreground
preference/your_environment/server/puma.rb
# true to server will be daemonize
daemonize false
Changing the document root
You must update the document root in the configuration file after moving your application structure to other directory.
on terminal
# move application directory
mv /path/to/app/root /path/to/after/app/root
preference/your_environment/server/puma.rb
#_app_root = '/path/to/app/root'
_app_root = '/path/to/new/app/root'
Using Other Web Servers
When you are not welcomed using Puma, you may use other one. A web server you will choose must suport Rack application such as unicorn
, thin
, mongrel
.
Starting with thin web server
on terminal
# move to your application root
cd /path/to/app/root
# adding thin to your Gemfile
echo "gem 'thin'" >> Gemfile
# installing thin
bundle install
# launch the web server
thin start
Setting Up SSL
Setting up SSL on your website is very easy. It’s just edit the server configuration file as follows.
preference/your_environment/server/puma.rb
ssl_bind _host, _port, {
key: '/path/to/your/private.key',
cert: '/path/to/your/certificate.crt'
}
or
bind "ssl://#{_host}:#{_port}?key=/path/to/your/private.key&cert=/path/to/your/certificate.crt"
Running nekonote server start
will launch the web server with enabling SSL.
Clients must request the server with https://
.
Debugging For Deamonized Server
When daemonize true
is set in preference/your_environment/server/puma.rb
you can’t see any messages on STDOUT nor STDERR.
That’s because file descriptors are closed.
In that case messages written to log/puma.stderr.log
or log/puma.stdout.log
by default.
Did you change the configuration and you can’t find such files? Then you must add the directive below.
preference/your_environment/server/puma.rb
stdout_redirect "#{_app_root}/log/puma.stdout.log", "#{_app_root}/log/puma.stderr.log"
The other way to see exception details about launching the web server is changing daemonize
to false
temporarily.