Where do values come from in nginx.conf.erb file?

Viewed 1164

I'm using Phusion Passenger with Rails (standalone) running on Heroku. The config file is passed in the Procfile settings.

I'd like to change the historical nginx.conf.erb file. I can easily add new values, but it isn't obvious to me where the variable values are coming from.

Examples from the file:

error_log '<%= @options[:log_file] %>' <% if @options[:log_level] >= LVL_DEBUG %>info<% end %>;
pid '<%= @options[:pid_file] %>';

or

<%= nginx_option :passenger_log_level, :log_level %>

or

<% for app in @apps %>
server {
    <% if app[:ssl] %>
        <% if app[:ssl_port] %>
            listen <%= nginx_listen_address(app) %>;
            listen <%= nginx_listen_address_with_ssl_port(app) %> ssl;
        <% else %>
            listen <%= nginx_listen_address(app) %> ssl;
        <% end %>
    <% else %>
        listen <%= nginx_listen_address(app) %>;
    <% end %>
    server_name <%= app[:server_names].join(' ') %>;

So where are @options, @app coming from?

1 Answers

If you are using nginx.conf.erb for Passenger Standalone I assume you only care about the options that apply to Passenger and not nginx. All passenger options start with prefix passenger_, there are some unique options commonly used across many applications such as pid_file, log_file, etc. that apply to both passenger and nginx but for Standalone, they will only apply to Passenger.

These options are coming from when you start your passenger process with command line options: bundle exec passenger start --log-level=3 --log-file=tmp.log. If no values are provided, they will use their default values. For example, default values for PID file and Log file are listed when you start passenger.

$ bundle exec passenger start
======= Phusion Passenger Standalone web server started =======
PID file: /Users/phusion/myapp/tmp/pids/passenger.3000.pid   1
Log file: /Users/phusion/myapp/log/passenger.3000.log        2
Environment: development                     3
Accessible via: http://0.0.0.0:3000/         4

You can stop Phusion Passenger Standalone by pressing Ctrl-C.
===============================================================

There are various ways you can set these options such as through command line, in Passengerfile.json, or through environment variables.

A tip is that you can also set binding.pry in nginx.conf.erb and see what @options and @apps contains in debug mode.

# Add this as to the top of nginx.conf.erb

<% require 'pry' %>
<% binding.pry %>

You can view docs here:

Starting a server

Command line options

Passenger Standalone

If you decide to use Passenger + Nginx, there will be additional options you care about such as @apps and values in @options that nginx itself requires and sets when it starts up. If using Passenger + Nginx, you'll only need to set two configuration options, passenger_enabled and passenger_root.

More details about Passenger + Nginx are in docs here:

Passenger + Nginx

Passenger + Nginx Configuration Reference

Related