OPNsense
  • Home
  • Help
  • Search
  • Login
  • Register

  • OPNsense Forum »
  • English Forums »
  • Web Proxy Filtering and Caching (Moderator: fabian) »
  • [SOLVED] NGinx tries to load individual certificate despite wildcard certificate
« previous next »
  • Print
Pages: [1] 2

Author Topic: [SOLVED] NGinx tries to load individual certificate despite wildcard certificate  (Read 5410 times)

psychofaktory

  • Full Member
  • ***
  • Posts: 104
  • Karma: 2
    • View Profile
[SOLVED] NGinx tries to load individual certificate despite wildcard certificate
« on: October 13, 2022, 01:31:58 pm »
Hello,

I have created a new HTTP server via the Nginx plugin. In the same way as many others before.
However, now I get the following error message for the newly created server after restarting the nginx service:
Code: [Select]
cannot load certificate "/usr/local/etc/nginx/key/subdomain.mydomain.tld.pem": BIO_new_file() failed (SSL: error:02001002:system library:fopen:No such file or directory:fopen('/usr/local/etc/nginx/key/subdomain.mydomain.tld.pem','r') error:2006D080:BIO routines:BIO_new_file:no such file)
The wildcard certificate (*.mydomain.tld) created via the ACME client was selected as the TLS certificate (as with the other HTTP servers).
The check mark for "Enable Let's Encrypt Plugin Support" is not set.

Where is the error and how can I force the use of the wildcard certificate?
« Last Edit: October 17, 2022, 05:21:49 pm by psychofaktory »
Logged

Fright

  • Hero Member
  • *****
  • Posts: 1777
  • Karma: 164
    • View Profile
Re: NGinx tries to load individual certificate despite wildcard certificate
« Reply #1 on: October 13, 2022, 04:45:29 pm »
Hi
i don't think it has anything to do with the certificate type (the setup script doesn't check the certificate contents). maybe there are errors in the backend log?
Or the "HTTPS Listen Address" is empty?
Logged

psychofaktory

  • Full Member
  • ***
  • Posts: 104
  • Karma: 2
    • View Profile
Re: NGinx tries to load individual certificate despite wildcard certificate
« Reply #2 on: October 13, 2022, 08:17:40 pm »
Quote from: Fright on October 13, 2022, 04:45:29 pm
maybe there are errors in the backend log?
Where can I find this log?

Quote from: Fright on October 13, 2022, 04:45:29 pm
Or the "HTTPS Listen Address" is empty?
No, its exactly the same configuration as in all other HTTP-servers which are working.


Edit:
No entry in the backend log of OPNsense -> System -> Logs.
« Last Edit: October 13, 2022, 08:31:25 pm by psychofaktory »
Logged

Fright

  • Hero Member
  • *****
  • Posts: 1777
  • Karma: 164
    • View Profile
Re: NGinx tries to load individual certificate despite wildcard certificate
« Reply #3 on: October 14, 2022, 09:16:40 pm »
hm. any messages (except "php_fpm already running?") if you run
Code: [Select]
/usr/local/opnsense/scripts/nginx/setup.php?
Logged

psychofaktory

  • Full Member
  • ***
  • Posts: 104
  • Karma: 2
    • View Profile
Re: NGinx tries to load individual certificate despite wildcard certificate
« Reply #4 on: October 15, 2022, 10:47:00 am »
Quote from: Fright on October 14, 2022, 09:16:40 pm
hm. any messages (except "php_fpm already running?") if you run
Code: [Select]
/usr/local/opnsense/scripts/nginx/setup.php?

No.
Just "php_fpm allready running? (pid=56775)."
Logged

psychofaktory

  • Full Member
  • ***
  • Posts: 104
  • Karma: 2
    • View Profile
Re: NGinx tries to load individual certificate despite wildcard certificate
« Reply #5 on: October 15, 2022, 11:03:29 am »
Found the error.

I had added the line "add_header 'Access-Control-Allow-Origin' '*';" for a previously created HTTP server in the nginx configuration via the xxxxxxxx-xxxx-xxxx-xxxxxxxx_post/*.conf.
This apparently led to the described error for all subsequently created HTTP servers.

After I removed the *.conf, the error disappeared.
Logged

psychofaktory

  • Full Member
  • ***
  • Posts: 104
  • Karma: 2
    • View Profile
Re: NGinx tries to load individual certificate despite wildcard certificate
« Reply #6 on: October 15, 2022, 11:10:57 am »
OK, I guess I spoke too soon.

When I then wanted to create another HTTP server (same setting, only different upstream and different subdomain), the error occurred again.
Logged

Fright

  • Hero Member
  • *****
  • Posts: 1777
  • Karma: 164
    • View Profile
Re: NGinx tries to load individual certificate despite wildcard certificate
« Reply #7 on: October 17, 2022, 01:21:55 pm »
Hi
i think i found some..and its a little regression at https://github.com/opnsense/plugins/commit/9f80395a3bfbc0a09c6d65d3cb0e9a66217e03e5
while trying to figure out how to solve it nifty, I see a temporary workaround for that by manually running '/usr/local/opnsense/scripts/nginx/setup.php' after adding the server with a new name and certificate and clicking the Apply button. In this case the certificate files will be in the right place and you will need to hit Apply again
« Last Edit: October 17, 2022, 01:23:37 pm by Fright »
Logged

franco

  • Administrator
  • Hero Member
  • *****
  • Posts: 17751
  • Karma: 1620
    • View Profile
Re: NGinx tries to load individual certificate despite wildcard certificate
« Reply #8 on: October 17, 2022, 01:33:50 pm »
Huh, why... is setup.php not called correctly? Which OPNsense version is this?


Cheers,
Franco
Logged

Fright

  • Hero Member
  • *****
  • Posts: 1777
  • Karma: 164
    • View Profile
Re: NGinx tries to load individual certificate despite wildcard certificate
« Reply #9 on: October 17, 2022, 01:39:06 pm »
@franco Hi)
 im testing on 22.7.6
/usr/local/etc/rc.d/nginx  contains "reload_precmd="nginx_checkconfig" which is called before _setup. so we have at Apply hit:
-templates reloaded (with new server certs references in nginx.conf)
-nginx fails config check (certs files not ready yet because setup.php is not yet started)
-setup not started because config check return error
« Last Edit: October 17, 2022, 01:58:26 pm by Fright »
Logged

Fright

  • Hero Member
  • *****
  • Posts: 1777
  • Karma: 164
    • View Profile
Re: NGinx tries to load individual certificate despite wildcard certificate
« Reply #10 on: October 17, 2022, 01:52:25 pm »
@franco
how dirty is that syntax for /etc/rc.conf.d/nginx :
Code: [Select]
reload_precmd="/usr/local/opnsense/scripts/nginx/setup.php; nginx_checkconfig"
restart_precmd="/usr/local/opnsense/scripts/nginx/setup.php; nginx_checkconfig"
nginx_enable="YES"
for cases like this?
Logged

franco

  • Administrator
  • Hero Member
  • *****
  • Posts: 17751
  • Karma: 1620
    • View Profile
Re: NGinx tries to load individual certificate despite wildcard certificate
« Reply #11 on: October 17, 2022, 02:07:16 pm »
It's supposed to call setup.php on start/reload/restart by default. Is nginx rc script fudging these actions somehow?


Cheers,
Franco
Logged

Fright

  • Hero Member
  • *****
  • Posts: 1777
  • Karma: 164
    • View Profile
Re: NGinx tries to load individual certificate despite wildcard certificate
« Reply #12 on: October 17, 2022, 02:11:56 pm »
if i understand this right at https://github.com/opnsense/src/blob/a72dccaa7d6ced2a547c5d7f7a739e0a494ee333/libexec/rc/rc.subr#L1185
_precmd is executed before _setup. and if _precmd fails (like in this case) _setup will not run.
or can we switch _setup/_precmd order?

nginx rc:
https://github.com/freebsd/freebsd-ports/blob/main/www/nginx/files/nginx.in
« Last Edit: October 17, 2022, 02:14:50 pm by Fright »
Logged

franco

  • Administrator
  • Hero Member
  • *****
  • Posts: 17751
  • Karma: 1620
    • View Profile
Re: NGinx tries to load individual certificate despite wildcard certificate
« Reply #13 on: October 17, 2022, 02:17:55 pm »
Yikes ok, nginx_checkconfig as precmd stops start/reload :(

In that case we need to switch indeed. Commit in a bit.


Thanks,
Franco
Logged

Fright

  • Hero Member
  • *****
  • Posts: 1777
  • Karma: 164
    • View Profile
Re: NGinx tries to load individual certificate despite wildcard certificate
« Reply #14 on: October 17, 2022, 02:20:05 pm »
Thanks !!  :)
Logged

  • Print
Pages: [1] 2
« previous next »
  • OPNsense Forum »
  • English Forums »
  • Web Proxy Filtering and Caching (Moderator: fabian) »
  • [SOLVED] NGinx tries to load individual certificate despite wildcard certificate
 

OPNsense is an OSS project © Deciso B.V. 2015 - 2024 All rights reserved
  • SMF 2.0.19 | SMF © 2021, Simple Machines
    Privacy Policy
    | XHTML | RSS | WAP2