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

Drupal multisite as subfolder #95

Open
heyyo-droid opened this issue Aug 23, 2024 · 3 comments
Open

Drupal multisite as subfolder #95

heyyo-droid opened this issue Aug 23, 2024 · 3 comments

Comments

@heyyo-droid
Copy link

heyyo-droid commented Aug 23, 2024

I'm struggling to create multisites as subfolders in a Drupal 10.

For example my Drupal website has this url: http://d10.docker.localhost

And my multisites should be of this form:

So inside my sites.php I have:

<?php

$sites["d10.docker.localhost.site1"] = "site1";
$sites["d10.docker.localhost.site2"] = "site2";

And each multisites have their own folder under /var/www/html/web/sites with settings.php with their own database (for now empty)

  • /var/www/html/web/sites/site1
  • /var/www/html/web/sites/site2

According Drupal 7 documentation (Doc for Drupal 8/9/10/11 was not updated), we also need to create symlinks for each multisite in web/ folder pointing to web.

So from /var/www/htm/web I did

ln -s . site1
ln -s . site2
chown -h 1000:82 site1 # to get correct owner/group
chown -h 1000:82 site2

If I test drush status inside multisite folder, I can see correct multisite detected.

So for Drupal, multisite seems correctly declared.

But when I browse urls:

  1. http://d10.docker.localhost/site1 returns a 404 from Drupal.
  2. http://d10.docker.localhost/site1/core/install.php returns a 404 from nginx.
  3. http://d10.docker.localhost/site1/core/misc/druplicon.png I got a 200 response

So according 3., it seems nginx follows correctly the symlinks, but according 2. and 3. it seems there is something wrong with priority and symlinks.

@heyyo-droid
Copy link
Author

If we replace nginx container with wodby apache, it works as expected.

@heyyo-droid
Copy link
Author

heyyo-droid commented Aug 23, 2024

@csandanov it looks like related to fastcgi_param SCRIPT_FILENAME $document_root/index.php;
$document_root is always /var/www/html/web but for multisite we need /var/www/html/web/site1 for example.

it looks like the variable $realpath_root fixed this according this article:
https://joshtronic.com/2019/07/29/symlinks-with-nginx-and-php-fpm/

https://nginx.org/en/docs/http/ngx_http_core_module.html#var_realpath_root

@heyyo-droid
Copy link
Author

So in the meantime, it's fixed in wodby nginx itself, I tried to use custom preset to see if my theory is exact.

So I created a preset called multisite from a copy of drupal 10 preset file.
And also a corresponding upstream config file.

By using this custom preset website is still working :-)

      NGINX_SERVER_ROOT: /var/www/html/web
      # NGINX_VHOST_PRESET: $NGINX_VHOST_PRESET
      NGINX_VHOST_PRESET: "multisite"
    volumes:
    - ./:/var/www/html:cached
    - ./nginx/multisite.conf.tmpl:/etc/gotpl/presets/multisite.conf.tmpl
    - ./nginx/upstream.multisite.conf.tmpl:/etc/gotpl/includes/upstream.multisite.conf.tmpl

Now it looks like replacing $document_root by $realpath_root is far from being enough...

For example those locations won't work for subfolders, so need to be also modified to allow any subfolder prefix, that could potentially open more security issues:

location = /index.php {
...
location = /core/install.php {
...
location = /core/rebuild.php {
...
location ~* ^/core/authorize.php {
...
location = /cron {
...
location ~* ^/update.php {
...

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

No branches or pull requests

1 participant