Custom Content Providers

A Content Provider provides the actual web content (html pages) that nginx-le is to serve.

Nginx-le ship with a number of standard content providers:

  • static - serve static HTML content from a local directory.

  • generic - proxy a generic HTTP application server.

  • tomcat - proxy the tomcat web application server.

If none of the above methods suite your model then you can create your own custom content provider.

In most cases you can use the generic option. For example, if you have a PHP or a Ruby web server then simply use one of the standard nginx docker containers for PHP or Ruby and then use the nginx-le 'generic' Content Provider to have nginx-le proxy your docker container.

If you select any of the three built in Content Providers nginx-le automatically generates the location and upstream files required by nginx.

A custom Content Provider is simply one that provides its own location and upstream files for nginx.

Location file

By default Nginx-le:

  • configures Nginx to look for the location files (within the container) in: /etc/nginx/include/*.location.

  • mounts the host path /opt/nginx/include into the container path /etc/nginx/include.

When you select Custom Content Provider you need to provide your own location file in /opt/nginx/include.

location files must be named with a '.location' extension.

You can place any number of nginx location files in the /opt/nginx/include/host directory and all *.location files be mounted the next time that the Nginx-LE container is started or nginx is reloaded.

This is an example location file for proxying the java Tomcat server.

This location file requires an upstream file (see the example below) to be functional.

location / {
        #try_files $uri $uri/ =404;

        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Proto https;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_redirect off;
        proxy_max_temp_file_size 0;
        proxy_pass http://tomcat/mycontext/;
        proxy_read_timeout 300;
}

location /mycontext {
        #try_files $uri $uri/ =404;

        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Proto https;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_redirect off;
        proxy_max_temp_file_size 0;
        proxy_pass http://tomcat/mycontext/;
        proxy_read_timeout 300;
}

Upstream servers

If you Nginx-LE needs to proxy your web application server then you will need to provide one or more .upstream files to configure the connection to those servers.

upstream files must be named with a '.upstream' extension.

By default Nginx-LE:

  • mounts the host path /opt/nginx/include into the container path /etc/nginx/include.

  • configures Nginx to look for the upstream files (within the container) in: /etc/nginx/include/*.upstream.

When you select Custom Content Provider you need to provide your own upstream file in /opt/nginx/include.

Nginx-LE will load any /opt/nginx/include/*.upstream files from the host system.

You can place any number of nginx upstream files in this directory and they will be mounted the next time that the Nginx-LE container is started or nginx is reloaded.

This is an example upstream file for proxying the java Tomcat server

upstream tomcat {
    server 127.0.0.1:8080 fail_timeout=0;
}

Last updated