nginx

Between managed server versions 5 and 8, we used nginx as the default web server. For several reasons, mostly regarding configuration and simplicity, we decided to switch to Apache with managed server version 9. Anyhow, we still provide nginx to run your website when you choose to do so.

Warning

This feature is meant for advanced users with in-depth nginx knowledge only. If you are in doubt, please contact us to define an expedient architecture.

Availability

nginx is available for all websites configured with the PHP type. We do not support nginx setups for any other types, and no application related templates are provided.

Setup

To activate nginx, make sure that the website type is set to PHP, and then select the Enable nginx checkbox in the corresponding website’s Advanced tab. This will:

  • install nginx and configure a virtual host for the current website, listening on localhost (127.0.0.1) port 51380

  • create a nginx configuration file in ~/cnf/nginx-server.conf, which is included into the nginx configuration at the server level of the current virtual host (see Server level below)

  • create a nginx configuration file in ~/cnf/nginx-http.conf, which is included into the nginx configuration at the http level (see HTTP level below)

  • create a .htaccess file within your webroot to proxy all requests to the nginx vhost

Apache will still be installed in front and used to:

Configuration

By default, a mostly empty nginx virtual host will be added. The configuration does consist of the following settings:

  • listen configuration: 127.0.0.1, port 51380 (non-configurable)

  • server name: taken from the server name configuration in Cockpit, which is used for the Apache website in front as well

  • webroot

  • access and error log configuration (~/log/nginx-access.log/~/log/nginx-error.log)

  • @php location to connect to PHP within your local configuration

There is no application or type related configuration whatsoever. Add any required settings to the server level configuration (see Server level below).

Tip

You can look into the website configuration located at /etc/nginx/sites-enabled/ by accessing the server as the devop user (see Generic Admin User).

Server level

The server level configuration is located at ~/cnf/nginx-server.conf and will be included within the server {} configuration of the current vhost. It can be used to alter the configuration of the current website, for example to define custom rewrite rules or headers.

A location to parse .php files through the PHP interpreter is added by default. Feel free to alter or remove this configuration according to your needs.

Tip

After changes, reload the configuration with the nginx-reload shortcut.

HTTP level

The HTTP level configuration is located at ~/cnf/nginx-http.conf and will be included within the http {} configuration of nginx. You can use this file for settings that must be configured within the HTTP context.

Warning

This global configuration will apply to all nginx enabled websites on the current server.