Skip to content
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

handle deprecated http2_push_preload conf for nginx >= 1.25.1 #1451

Merged
merged 7 commits into from
Dec 21, 2023

Conversation

OpJePl44tsm4n
Copy link
Contributor

Updated the config so it will work for fresh installs.

removed http2 and http2_push_preload because they are deprecated in latest Nginx versions.

@drbyte
Copy link
Contributor

drbyte commented Oct 6, 2023

I agree that this is the correct fix.

Unfortunately it only works if the Nginx version is 1.25.1 or greater, which is quite new. The changed syntax is not backward-compatible. (Ref: nginx docs )

2023-08-15 | nginx-1.25.2 mainline version has been released.
2023-06-13 | nginx-1.25.1 mainline version has been released.

If someone is using (or is forced to use) an older Nginx version, they will get the following anytime they run valet secure or re-secure their sites with valet tld, and Valet will refuse to work until the old syntax is restored to all the "secured" Sites configs.

  Nginx cannot start; please check your nginx.conf [1: nginx: [warn] protocol options redefined for 127.0.0.1:443 in ~/.config/valet/Nginx/foo.test:9
  nginx: [emerg] unknown directive "http2" in ~/.config/valet/Nginx/foo.test:15
  nginx: configuration file /usr/local/etc/nginx/nginx.conf test failed
  ].

@mattstauffer how do you feel about incorporating nginx-version-detection so we can handle version-specific stub file handling?

@OpJePl44tsm4n
Copy link
Contributor Author

@drbyte thank you for your response, I was thinking about that. Without a mayor version bump, probably a version check would be needed, since installing Valet requires the latest nginx version by default.

I'll take a look and will update the PR.

@drbyte
Copy link
Contributor

drbyte commented Oct 7, 2023

At least the old syntax is not throwing Fatal errors and preventing Nginx from starting.
Unfortunately the new syntax does throw fatal errors on older Nginx versions. 😢

@OpJePl44tsm4n
Copy link
Contributor Author

@drbyte true but fresh installs will require lates version of nginx so now it's broken as is.
option is to cap the nginx version in the install command and update this part.

$this->brew->installOrFail('nginx', []);

my suggestion is to add a check in Site.php to check the nginx version and require
secure.valet.outdated.config for the older versions. This would make it work for all versions.

I'll make a fix so you can check it.

@@ -631,8 +631,11 @@ public function buildCertificateConf(string $path, string $url): void
public function buildSecureNginxServer(string $url, string $siteConf = null): string
{
if ($siteConf === null) {
$nginxVersion = ltrim(exec('nginx -v'), 'nginx version: nginx/');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since ltrim() technically doesn't support passing a "phrase" (it treats it as a bunch of characters, not a phrase), perhaps simply str_replace() might be better?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Thx. 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@OpJePl44tsm4n perhaps also rework the Title of this PR slightly to incorporate "http2" into it?
Maybe something like "handle deprecated http2_push_preload conf for nginx >= 1.25.1" ?

@drbyte
Copy link
Contributor

drbyte commented Oct 10, 2023

@mattstauffer @driesvints I think this is ready for merge.

Of course, feel free to test on your local machine before+after upgrading nginx via brew

@OpJePl44tsm4n OpJePl44tsm4n changed the title fix secure.valet.conf format for nginx >= 1.25.1 handle deprecated http2_push_preload conf for nginx >= 1.25.1 Oct 10, 2023
version to string
@mattstauffer
Copy link
Collaborator

@drbyte thank you so much for reviews and back-and-forths! Again, apologies for my delay here. @OpJePl44tsm4n thank you for this PR!

Testing now, and will merge if it doesn't bonk things for me.

@mattstauffer mattstauffer merged commit 47847d5 into laravel:master Dec 21, 2023
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

Successfully merging this pull request may close these issues.

3 participants