Web servers

Customize the web server #

Buildpacks allow you to customize the web server for your application. Nginx and Apache2 are supported.

Environment variables #

In case you want to adjust the default document root for your application (in your repository), you can set the path using the runway CLI:

runway config set BP_WEBSERVER_ROOT=app/public

… or set it in project.toml:

[ build ]
  [[ build.env ]]

Other variables are available in their designated buildpacks:

Server configuration file #

By including a configuration file in the root of your application repository, you can go all the way.

For nginx it’s an nginx.conf and for Apache2 it’s a httpd.conf. Make sure either configuration file configures the entire server (not a single virtual host).

For example, to configure nginx to use the user’s actual IP address, the following snippet will give you an idea for what is expected:

worker_processes 1;
daemon off;

error_log stderr;

events {
  worker_connections 1024;

http {
  charset utf-8;
  access_log /dev/stdout;
  default_type application/octet-stream;
  include mime.types;
  sendfile on;

  tcp_nopush on;
  keepalive_timeout 30;
  # Ensure that redirects don't include the internal container PORT - 8080
  port_in_redirect off;

  real_ip_header X-Forwarded-For;

  server {
    listen {{port}};
    # snip
Don’t forget to add the listen {{port}}; directive and avoid hard-coding this setting.