Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

bufferoverflow's avatar

Nginx variable not working

I allow my app user's to use a custom domain. So i set up a regex server name to catch the domain in a variable and serve the correct letsencrypt certificate:

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;

    server_name ~^(www\.)?(?<domain>.+)$;
    root /home/forge/myapp.com/public;

    # This works
    add_header X-testvar /etc/nginx/ssl/$domain/xxxxx/server.crt;
    
    # This makes nginx crash (domain variable)
    ssl_certificate /etc/nginx/ssl/$domain/xxxxx/server.crt;
    
    # This works (hardcoded domain)
    ssl_certificate /etc/nginx/ssl/myapp.com/xxxxx/server.crt;

Edit: Just found out variables can be used in the ssl_certificate path, but they affect the performance. So, is the only option to create a new server block for every customer's domain name?

0 likes
0 replies

Please or to participate in this conversation.