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

Support multiple docroots for projects #1850

Closed
arysom opened this issue Sep 26, 2019 · 9 comments
Closed

Support multiple docroots for projects #1850

arysom opened this issue Sep 26, 2019 · 9 comments

Comments

@arysom
Copy link

arysom commented Sep 26, 2019

There is a Yii framework written in PHP and it has advanced template. They even have their own docker setup, which I've tried and failed. The advanced template consists of project root and two separate directories frontend backend which are two different domains that use the project root - probably directory common is important.

I would like to have one ddev setup pointing to two different directories with two different domains and share the base.

I've tried to modify docker-compose inside .ddev folder.

Is it even possible now maybe? I can fire up frontend and backend separately but not at the same time.

Thank you.

@rfay
Copy link
Member

rfay commented Sep 26, 2019

Hi @arysom -

If I understand right you're talking about two different webservers with two different docroots. There are a number of ways to approach this:

  1. Run two ddev projects that talk to each other.. (In the faq). Use the same code for each.
  2. Run one of the projects as a 3rd-party service, it might even use the ddev-webserver container, but as a separate instance. This stackoverflow answer shows that technique. Big picture of additional services is in the docs
  3. Do custom nginx configuration that handles both docroots. This seems like the most complex of the options.
  4. It might be possible to put two different ddev projects at different subdirectories of the project. I don't know any of the details. For example, if a code project had two directories, "frontend" and "backend" you could ddev config in each of those and you'd have two ddev projects but one set of code.

@arysom
Copy link
Author

arysom commented Sep 27, 2019

I've tried 2. and 4. but can't make it. I think I'll go with custom nginx configuration.

@arysom
Copy link
Author

arysom commented Sep 30, 2019

Hi @rfay . I've reported this issue as "feature request" . This could be useful if we could easily add two webroots at the same time. But of course it would be a bonus. I'm satisfied how the ddev now works and I recommend this project. Feel free to close this issue. Thank you.

@rfay
Copy link
Member

rfay commented Sep 30, 2019

Thanks @arysom - Could you give some detail here about how you solved it? Alternately, do a PR with more extensive description of how to solve it in https://github.com/drud/ddev-contrib

@arysom
Copy link
Author

arysom commented Sep 30, 2019

I mean I would like to request such feature :) For now, I haven't solved this yet.

@rfay rfay changed the title Yii 2 advanced project template Yii 2 advanced project template: Support two separate docroots Oct 5, 2019
@rfay
Copy link
Member

rfay commented Oct 18, 2019

@arysom you should take a look at the solution in #1889

@rfay rfay changed the title Yii 2 advanced project template: Support two separate docroots Support multiple docroots for projects Oct 23, 2019
@arysom
Copy link
Author

arysom commented Oct 29, 2019

Hi @rfay ,
this could be solution, I confirm that the second hostname appeared after ddev start . I've set webroot up one dir and set in nginx-site.conf $WEBSERVER_DOCROOT/frontend/web and $WEBSERVER_DOCROOT/backend/web respectively.

# Set https to 'on' if x-forwarded-proto is https
map $http_x_forwarded_proto $fcgi_https {
    default off;
    https on;
}

server {
    listen 80;
    listen [::]:80 default ipv6only=on;

    # The WEBSERVER_DOCROOT variable is substituted with
    # its value when the container is started.
    root $WEBSERVER_DOCROOT/frontend/web;

    include /etc/nginx/monitoring.conf;

    include /etc/nginx/nginx_default.conf;
    include /mnt/ddev_config/nginx/*.conf;
}


server {
    listen 443 ssl;
    listen [::]:443 default ipv6only=on;

    # The WEBSERVER_DOCROOT variable is substituted with
    # its value when the container is started.
    root $WEBSERVER_DOCROOT/frontend/web;

    ssl_certificate /etc/ssl/certs/master.crt;
    ssl_certificate_key /etc/ssl/certs/master.key;

    include /etc/nginx/monitoring.conf;

    include /etc/nginx/nginx_default.conf;
    include /mnt/ddev_config/nginx/*.conf;
}

#######################################################
# EXAMPLE SITE ADDED TO DEFAULT NGINX
# THIS ASSUMES server_name: matches a name added to 
# additional_hostnames: in your config.yaml
# 
# CANADA - EN
#######################################################
server {
    listen 80;

    server_name mybackendhostname.ddev.site;

    #redifne your root
	root $WEBSERVER_DOCROOT/backend/web;

    include /etc/nginx/nginx_default.conf;
}

Also I've set additional hostnames option in config.yaml

additional_hostnames:
  - mybackendhostname

Maybe someone could write a line about this in docs.

Thank you.

@gilbertsoft
Copy link
Member

What about adding something like this include /mnt/ddev_config/nginx/sites/*.conf; after the last server block? This would avoid to override the whole configuration and add the possibility to add new servers. Same for Apache ofc

@rfay
Copy link
Member

rfay commented Dec 7, 2019

I'm going to close this one in favor of #1889 , thanks all!

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

3 participants