Project: Lagoon (App Definition and Development / Application Definition & Image Build)
File: subfolders.md

An example could be: `www.example.com` points to one Drupal site, while `www.example.com/blog` loads a blog built in another Drupal. It would be possible to run both Drupals in a single Git repository and deploy it as a whole, but this workflow might not fit every team, and having separate Git repositories fits some situations better. The root application \(in this example, the Drupal site for `www.example.com`\), needs a couple of NGINX configs that will configure NGINX to be a reverse proxy to the subfolder applications: Create a file called `location_prepend.conf` in the root of your Drupal installation: ```text title="location_prepend.conf" resolver 8.8.8.8 valid=30s; location ~ ^/subfolder { setifempty $httpxforwarded_proto $scheme; proxysetheader X-Forwarded-For $proxyaddxforwardedfor; proxysetheader X-Forwarded-Proto $scheme; proxysetheader X-Forwarded-Proto $httpxforwarded_proto; proxysetheader X-Lagoon-Forwarded-Host $host; proxysetheader X-REVERSEPROXY $hostname; proxysetheader FORWARDED ""; proxysetheader Proxy ""; proxysslserver_name on; set $subfolderdrupalhost "https://nginx-lagoonproject-${LAGOONGITSAFE_BRANCH}.clustername.com:443"; proxypass $subfolderdrupal_host; proxysetheader Host $proxy_host; expires off; # make sure we honor cache headers from the proxy and not overwrite them ``` Replace the following strings: `/subfolder` with the name of the subfolder you want to use. For example, `/blog`. `nginx` with the service that you want to point too in the subfolder project. `lagoonproject` with the Lagoon projectname of the subfolder project. Add the following to your NGINX Dockerfile \(`nginx.dockerfile` or `Dockerfile.nginx`\): ```text title="nginx.dockerfile" COPY locationprepend.conf /etc/nginx/conf.d/drupal/locationprepend.conf RUN fix-permissions /etc/nginx/conf.d/drupal/* ``` Like the root application, we also need to teach the subfolder application \(in this example, the Drupal installation for `www.example.com/blog`\), that it is running under a subfolder. To do this, we create two files: Create a file called `locationdrupalappend_subfolder.conf` in the root of your subfolder Drupal installation: ```text title="locationdrupalappend_subfolder.conf" fastcgiparam SCRIPTNAME /subfolder/index.php; fastcgiparam HTTPHOST $http_host; fastcgiparam HTTPHOST $httpxlagoonforwardedhost ifnotempty; ``` Replace `/subfolder` with the name of the subfolder you want to use. For example, `/blog`. Create a file called `serverprependsubfolder.conf` in the root of your subfolder Drupal installation: ```text title="serverprependsubfolder.conf" include /etc/nginx/helpers/010_redirects.conf; rewrite ^/subfolder/(.*) /$1 last; absolute_redirect off; rewrite ^/subfolder /subfolder/ permanent; rewrite ^\/(.*) /subfolder/$1 permanent; ``` Replace `/subfolder` with the name of the subfolder you want to use. For example, `/blog`. We also need to modify the NGINX Dockerfile. Add the following to your NGINX Dockerfile \(`nginx.dockerfile` or `Dockerfile.nginx`\): ```text title="nginx.dockerfile" COPY locationdrupalappendsubfolder.conf /etc/nginx/conf.d/drupal/locationdrupalappendsubfolder.conf COPY serverprependsubfolder.conf /etc/nginx/conf.d/drupal/serverprependsubfolder.conf RUN fix-permissions /etc/nginx/conf.d/drupal/* ```