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

Tenancy for Laravel considers www. as a tenant #1087

Open
Guzbyte-tech opened this issue Mar 11, 2023 · 10 comments
Open

Tenancy for Laravel considers www. as a tenant #1087

Guzbyte-tech opened this issue Mar 11, 2023 · 10 comments
Assignees
Labels

Comments

@Guzbyte-tech
Copy link

Guzbyte-tech commented Mar 11, 2023

Bug description

The package considers any prefix before the main domain as a tenant and hence throws the error Tenant could not be identified on domain on TenantCouldNotBeIdentifiedOnDomainException. This error doesn't appear on localhost till i deployed to production server.

Steps to reproduce

After creating tenants, I tried accessing tenants from the browser i observed it has a prefix of www.
This then throughs an error www.tenant not identified on domain

Expected behavior

It is expected that the package should ignore the www. prefix before the tenant or accommodate without through the tenant not found error.

Laravel version

8.2.0

stancl/tenancy version

3.1.0

@Guzbyte-tech Guzbyte-tech added the bug Something isn't working label Mar 11, 2023
@stancl
Copy link
Member

stancl commented Mar 12, 2023

This is meant to be handled at the webserver level by redirecting www. domains to the non-www version.

That said, in v4 we might add some behavior to ignore a configurable list of subdomains.

@stancl stancl removed the bug Something isn't working label Mar 12, 2023
@Guzbyte-tech
Copy link
Author

Alright, I was able to fix this from the web server by creating the correct DNS records A record for * and www and also forcing redirect from www. to non-www through the nginx server config. I also installed an SSL certificate and the problem was solved.

But I still think this should be looked into to ignore the www.

This is an amazing package.

@stancl
Copy link
Member

stancl commented Mar 14, 2023

Will keep this open so that I remember to revisit this 👍🏻

@stancl stancl reopened this Mar 14, 2023
@luke-joseph
Copy link

That said, in v4 we might add some behavior to ignore a configurable list of subdomains.

This would be super useful in my opinion.

I'm currently trying to create a subdomain endpoint (create.myapp.com) that will take a request and create a tenant and initialize their site but it's proving difficult at the moment as I keep running into the TenantCouldNotBeIdentifiedOnDomainException.

Thanks for the awesome package!

@Sharifur
Copy link

Sharifur commented Apr 12, 2023

I am facing same issue as well, can you please share a record details @Guzbyte-tech
i need this solution for custom domain. i am able to resolve central domain www issue

[update]

resolved my problem by create a custom middleware. might not a best solution for it working for now. waiting for fore update in this issue

middleware ->
https://gist.github.com/Sharifur/eab15a572fd6e5ef77c0604964e77e15

@stancl stancl added the v4 label Apr 24, 2023
@geekasso
Copy link

geekasso commented May 4, 2023

I ended up creating a config file with 'blocked_subdomains' => [] and 'blocked_domains' => [] arrays. During registration, for instance, the function checks against the 'blocked_subdomains' array in the config file and if there is a match, it fails. I use the same method when adding tenant domains, but it checks against the 'blocked_domains' array.

----- Edit ----
I used a config file so that I can easily update it without committing code. Hopefully, this is a good implementation.

@Guzbyte-tech
Copy link
Author

Guzbyte-tech commented May 4, 2023

@Sharifur nginx config file

server {
server_name example.com www.example .com;
root /var/www/example.com/public;

add_header X-Frame-Options "SAMEORIGIN";
add_header X_XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";

index index.html index.htm index.php;

charset utf-8;

location / {
try_files $uri $uri/ /index.php?$query_string;
}

location = /favicon.ico { access_log off; log_out_found off; }
location = /robots.txt { access_log off; log_out_found off; }

error_page 404 /index.php;

location ~ .php$ {
fastcgi_pass un ix:/var/run/php/php7.4-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}

location ~/.(?!well-known).* {
deny all;
}
}

@Sharifur
Copy link

i will try it..

@Sharifur
Copy link

Sharifur commented Mar 9, 2024

any update about v4?

@stancl
Copy link
Member

stancl commented Mar 9, 2024

For updates about v4, follow our Discord.

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

5 participants