Skip to content

Add HTTP/2 Support for NGINX in Heroku PHP Buildpack ? #786

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
larsschenk opened this issue Apr 6, 2025 · 0 comments
Open

Add HTTP/2 Support for NGINX in Heroku PHP Buildpack ? #786

larsschenk opened this issue Apr 6, 2025 · 0 comments

Comments

@larsschenk
Copy link

I am using the Heroku PHP Buildpack with Router 2.0 enabled, which supports HTTP/2 between the client and the router. However, the communication between the Heroku Router and the Dyno still uses HTTP/1.1 because the NGINX configuration in the buildpack does not enable HTTP/2 (h2c). This limits the performance benefits of HTTP/2, especially for parallel requests.

Problem
The current NGINX configuration (conf/nginx/heroku.conf.php) does not enable HTTP/2 for the connection between the Router and the Dyno. Since Heroku terminates TLS at the Router, the Dyno must support HTTP/2 without TLS (h2c). NGINX (version 1.26.3 in the buildpack) supports h2c, but it needs to be explicitly enabled in the configuration.

Proposed Solution
I suggest adding HTTP/2 support by modifying the listen directive in the server block of the NGINX configuration. The change is minimal:

Current:
nginx

listen <?=getenv('PORT')?:'8080'?>;

Proposed:
nginx

listen <?=getenv('PORT')?:'8080'?>;
<?php if (getenv('HEROKU_PHP_NGINX_HTTP2')) { ?>
  http2 on;
<?php } ?>

To make this optional and backward-compatible, you could introduce an environment variable (e.g., HEROKU_PHP_NGINX_HTTP2) to control whether HTTP/2 is enabled:

heroku config:set HEROKU_PHP_NGINX_HTTP2=1

Benefits
Improved performance for parallel requests due to HTTP/2 multiplexing between Router and Dyno.

Better utilization of Router 2.0's HTTP/2 capabilities.

Minimal change with optional activation to avoid breaking existing setups.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant