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

[Help] How to use dynamic wildcard subdomains? #2041

Closed
edamov opened this issue Mar 12, 2019 · 5 comments
Closed

[Help] How to use dynamic wildcard subdomains? #2041

edamov opened this issue Mar 12, 2019 · 5 comments
Labels

Comments

@edamov
Copy link

edamov commented Mar 12, 2019

How I need to configure laradock for supporting dynamic wildcard subdomains for web applications.

I want to have an opportunity to make requests to http://<subdomain>.api.site from my host.
For example, app1.api.site, app2.api.site, app999.api.site etc
I'm using nginx webserver.

But I don't understand how I can configure it. Can anyone help me please?

@edamov edamov changed the title [Help] How to use wildcard subdomains? [Help] How to use dynamic wildcard subdomains? Mar 12, 2019
@bbashy
Copy link

bbashy commented Mar 19, 2019

I made nginx/sites/all.conf file and added the contents below.

This will match any domain.tld and subdomain.domain.tld and direct it to a folder for the $domain var.

server {

    listen 80;
    listen [::]:80;

    server_name ~^(?<domain>[^.]+)\.(?<tld>[^.]+)$;

    root /var/www/$domain/public;
    index index.php index.html;

    location / {
         try_files $uri $uri/ /index.php$is_args$args;
    }

    location ~ \.php$ {
        try_files $uri /index.php =404;
        fastcgi_pass php-upstream;
        fastcgi_index index.php;
        fastcgi_buffers 16 16k;
        fastcgi_buffer_size 32k;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        #fixes timeouts
        fastcgi_read_timeout 600;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }

    location /.well-known/acme-challenge/ {
        root /var/www/letsencrypt/;
        log_not_found off;
    }

    error_log /var/log/nginx/$domain-error.log;
    access_log /var/log/nginx/$domain-access.log;
}

server {

    listen 80;
    listen [::]:80;

    server_name ~^((?<subdomain>.*)\.)(?<domain>[^.]+)\.(?<tld>[^.]+)$;

    root /var/www/$domain/public;
    index index.php index.html;

    location / {
         try_files $uri $uri/ /index.php$is_args$args;
    }

    location ~ \.php$ {
        try_files $uri /index.php =404;
        fastcgi_pass php-upstream;
        fastcgi_index index.php;
        fastcgi_buffers 16 16k;
        fastcgi_buffer_size 32k;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        #fixes timeouts
        fastcgi_read_timeout 600;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }

    location /.well-known/acme-challenge/ {
        root /var/www/letsencrypt/;
        log_not_found off;
    }

    error_log /var/log/nginx/$domain-error.log;
    access_log /var/log/nginx/$domain-access.log;
}

@stale
Copy link

stale bot commented Feb 2, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Stale label Feb 2, 2020
@stale
Copy link

stale bot commented Feb 23, 2020

Hi again 👋 we would like to inform you that this issue has been automatically closed 🔒 because it had not recent activity during the stale period. We really really appreciate your contributions, and looking forward for more in the future 🎈.

@stale stale bot closed this as completed Feb 23, 2020
@tainmar
Copy link

tainmar commented Apr 23, 2020

@bbashy any idea on why this is not the default file ? It is great.

@bbashy
Copy link

bbashy commented Apr 23, 2020

@tainmar No idea. Submit a PR if you think it's useful :)

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

No branches or pull requests

3 participants