In order to have the Paketo HTTPD Server Buildpack generate an httpd.conf
for
your application the build process must have BP_WEB_SERVER
set to httpd
.
pack build httpd-no-config --path app \
--buildpack paketo-buildpacks/httpd \
--builder paketobuildpacks/builder-jammy-full:latest \
--env BP_WEB_SERVER=httpd
docker run --tty --rm --env PORT=8080 --publish 8080:8080 httpd-no-config
curl -s localhost:8080
That address can also be viewed in your browser.
By default the Paketo HTTPD Server Buildpack generates a httpd.conf
that has
public
as the server root directory. This can be configured by setting
BP_WEB_SERVER_ROOT
to either an absolute path or a path relative to the app
directory. To see this in action feel free to move or rename the public
directory inside of the app, for demonstration purposes we will rename public
to htdocs
.
mv app/public app/htdocs && \
pack build httpd-custom-root --path app \
--buildpack paketo-buildpacks/httpd \
--builder paketobuildpacks/builder-jammy-full:latest \
--env BP_WEB_SERVER=httpd \
--env BP_WEB_SERVER_ROOT=htdocs \
&& mv app/htdocs app/public
docker run --tty --rm --env PORT=8080 --publish 8080:8080 httpd-custom-root
curl -s localhost:8080
The Paketo HTTPD Server Buildpack allows you to set up push state for your
application. This means that regardless of the route that is requested,
index.html
will always be serverd. This comes in handy if you are serving a
Javascript frontend app where the route exists within the app but not on the
static file structure.
pack build httpd-push-state --path app \
--buildpack paketo-buildpacks/httpd \
--builder paketobuildpacks/builder-jammy-full:latest \
--env BP_WEB_SERVER=httpd \
--env BP_WEB_SERVER_ENABLE_PUSH_STATE=true
docker run --tty --rm --env PORT=8080 --publish 8080:8080 httpd-push-state
You should see the contents of index.html
regardless of what route you visit
curl -s localhost:8080/test
The Paketo HTTPD Server Buildpack allows you to force any HTTP request made to the server to be redirected using the HTTPS protocol.
pack build httpd-force-https --path app \
--buildpack paketo-buildpacks/httpd \
--builder paketobuildpacks/builder-jammy-full:latest \
--env BP_WEB_SERVER=httpd \
--env BP_WEB_SERVER_FORCE_HTTPS=true
docker run --tty --rm --env PORT=8080 --publish 8080:8080 httpd-force-https
You should see a HTTP status code 301 and the redirect address should be using the HTTPS protocol.
curl http://localhost:8080
The Paketo HTTPD Server Buildpack allows you to set up basic authentication
through a service binding of type
htpasswd
. The file structure for the
binding looks as follows:
binding
├── type
└── .htpasswd
To generate the .htpasswd
file for the binding the htpasswd
command line
tool that is an httdp utility was used. For sample purposes the user added was
user
and the password is password
.
pack build httpd-basic-auth --path app \
--buildpack paketo-buildpacks/httpd \
--builder paketobuildpacks/builder-jammy-full:latest \
--volume "$(pwd)/binding:/bindings/auth" \
--env BP_WEB_SERVER=httpd \
--env SERVICE_BINDING_ROOT=/bindings
docker run --tty --rm \
--env PORT=8080 \
--env SERVICE_BINDING_ROOT=/bindings \
--publish 8080:8080 \
--volume "$(pwd)/binding:/bindings/auth" \
httpd-basic-auth
A standard with curl -s localhost:8080
you should see an HTTP status code 401
returned. Run the following:
curl -u user:password localhost:8080