phpnginx

package module
v0.3.30 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 22, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

README

PHP Nginx Cloud Native Buildpack

A Cloud Native Buildpack for configuring Nginx settings for PHP apps.

The buildpack generates the Nginx configuration file with the minimal set of options to get Nginx to work with FPM (FastCGI Process Manager), and incorporates configuration from users and environment variables. The final Nginx configuration file is available at /workspace/nginx.conf, or locatable through the buildpack-set $PHP_NGINX_PATH environment variable at launch-time.

Integration

The PHP Nginx CNB provides php-nginx-config, which can be required by subsequent buildpacks. In order to configure Nginx, the user must declare the intention to use Nginx as the web-server by setting the $BP_PHP_SERVER environment variable to nginx at build-time.

pack build my-nginx-app --env BP_PHP_SERVER="nginx"

Nginx Configuration Sources

The base configuration file generated in this buildpack includes some default configuration, FPM-specific configuration, and has include sections for user-included configuration.

FPM-specific Configuration

This buildpack is written to provide Nginx configuration that should always be used in conjunction with FPM. The Nginx configuration file is generated to include FPM-specific configuration. This buildpack also sets up an FPM configuration file with Nginx-specific socket settings and makes it available in the /workspace.

User Included Configuration

User-included configuration should be found in the application source directory under <app-directory>/.nginx.conf.d/. Server-specific configuration should be inside a file named *-server.conf, and HTTP configuration should be inside a file with the naming structure *-http.conf.

If files at these paths exist, it will be included in include sections at the appropriate places in the generated Nginx configuration.

Environment Variables

The following environment variables can be used to override default settings in the Nginx configuration file.

Variable Default
BP_PHP_NGINX_ENABLE_HTTPS false
BP_PHP_ENABLE_HTTPS_REDIRECT true
BP_PHP_WEB_DIR htdocs

Note that for HTTPS workloads, setting $BP_PHP_NGINX_ENABLE_HTTPS sets all connections to work in SSL mode. You may still need to add a user-included config file to provide directives like ssl_certificate, ssl_certificate_key etc.

Usage

To package this buildpack for consumption:

$ ./scripts/package.sh

This builds the buildpack's Go source using GOOS=linux by default. You can supply another value as the first argument to package.sh.

Run Tests

To run all unit tests, run:

./scripts/unit.sh

To run all integration tests, run:

./scripts/integration.sh

Debug Logs

For extra debug logs from the image build process, set the $BP_LOG_LEVEL environment variable to DEBUG at build-time (ex. pack build my-app --env BP_LOG_LEVEL=DEBUG or through a project.toml file.

Documentation

Index

Constants

View Source
const (
	PhpNginxConfigLayer = "php-nginx-config"
	PhpNginxConfig      = "php-nginx-config"
)

Variables

View Source
var NGINXConfTemplate string
View Source
var NGINXFPMConfTemplate string

Functions

func Build

func Build(nginxConfigWriter ConfigWriter, nginxFpmConfigWriter ConfigWriter, logger scribe.Emitter) packit.BuildFunc

Build will return a packit.BuildFunc that will be invoked during the build phase of the buildpack lifecycle.

Build will create a layer dedicated to Nginx configuration, configure default Nginx settings, incorporate other configuration sources, and make the configuration available at both build-time and launch-time.

func Detect

func Detect() packit.DetectFunc

Types

type ConfigWriter

type ConfigWriter interface {
	Write(workingDir string) (string, error)
}

ConfigWriter sets up the default Nginx configuration file and incorporates any user configurations.

type NginxConfig

type NginxConfig struct {
	UserServerConf       string
	UserHttpConf         string
	EnableHTTPS          bool
	DisableHTTPSRedirect bool
	AppRoot              string
	WebDirectory         string
	FpmSocket            string
}

type NginxConfigWriter

type NginxConfigWriter struct {
	// contains filtered or unexported fields
}

func NewNginxConfigWriter

func NewNginxConfigWriter(logger scribe.Emitter) NginxConfigWriter

func (NginxConfigWriter) Write

func (c NginxConfigWriter) Write(workingDir string) (string, error)

type NginxFpmConfig

type NginxFpmConfig struct {
	FpmSocket string
}

type NginxFpmConfigWriter

type NginxFpmConfigWriter struct {
	// contains filtered or unexported fields
}

func NewFpmNginxConfigWriter

func NewFpmNginxConfigWriter(logger scribe.Emitter) NginxFpmConfigWriter

func (NginxFpmConfigWriter) Write

func (c NginxFpmConfigWriter) Write(workingDir string) (string, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL