-
Notifications
You must be signed in to change notification settings - Fork 81
Reverse proxy in DDEV cluster #2999
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
Changes from all commits
2f79384
a8d4f45
07c16c7
edd500e
04cbbfc
d55279f
12058fd
565b58b
edc40d6
fb8644b
5f028d2
1aad23b
ce983eb
ec04b5f
f99b46a
1fa6804
e1a671a
528563b
e3bfc13
c8eb0ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,129 @@ | |
|
|
||
| To run an [[= product_name_cloud =]] project locally, you may refer to [DDEV and Ibexa Cloud](ddev_and_ibexa_cloud.md) instead. | ||
|
|
||
| ## Install reverse proxy | ||
|
|
||
| A reverse proxy can be added to the cluster to enable [HTTP caching](http_cache.md). | ||
|
|
||
| ### Varnish | ||
|
|
||
| The following sequence of commands: | ||
|
|
||
| 1. Sets a variable with the desired Varnish version, here Varnish 7.1 | ||
| 2. Copies and customizes `parameters.vcl` file in `.ddev/varnish/` (which is mounted as `/etc/varnish/` into the container): | ||
| - sets `web` container as the backend host and an invalidator (so back office can purge cache) | ||
| - adds "all IPs" CIDR notation to `debuggers` list to allow debugging from any IP | ||
| - on Varnish 7, enable logging of access control list matching for both `invalidators` and `debuggers` lists | ||
| (new Varnish 7 syntax, it was enabled by default on previous versions) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel this could be part of HTTP cache doc - and just linked from here
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mnocon I found no clear ACL explanation in our doc to add a |
||
| 3. Sets main `varnish*.vcl` file to use and "path to VCL directory" argument name depending on Varnish version | ||
| 4. Copies the main VCL file to `.ddev/varnish/` | ||
| 5. Sets the Varnish version to use and its demon starting parameters to use the files | ||
| 6. Adds the Varnish container | ||
| 7. Sets Varnish as the HTTP cache server | ||
| 8. Restarts the DDEV cluster and clear the [[= product_name =]] cache | ||
|
|
||
| ```bash | ||
| VARNISH_VERSION=7.1 | ||
| mkdir -p .ddev/varnish | ||
| sed 's/.host = "127.0.0.1";/.host = "web";/' vendor/ibexa/http-cache/docs/varnish/vcl/parameters.vcl > .ddev/varnish/parameters.vcl | ||
|
adriendupuis marked this conversation as resolved.
|
||
| sed -i '/^acl invalidators {$/a \\ "web";' .ddev/varnish/parameters.vcl | ||
| sed -i '/^acl debuggers {$/a \\ "0.0.0.0"/0; \/\/ debug from any IP' .ddev/varnish/parameters.vcl | ||
| if [[ $VARNISH_VERSION == 7.* ]]; then | ||
| sed -i 's/acl invalidators {/acl invalidators +log {/' .ddev/varnish/parameters.vcl | ||
| sed -i 's/acl debuggers {/acl debuggers +log {/' .ddev/varnish/parameters.vcl | ||
| vcl_path=vcl_path | ||
| vcl_file=varnish7.vcl | ||
| elif [[ $VARNISH_VERSION == 6.* ]] | ||
| vcl_path=vcl_dir | ||
| vcl_file=varnish6.vcl | ||
| fi | ||
| cp vendor/ibexa/http-cache/docs/varnish/vcl/$vcl_file .ddev/varnish/ | ||
| ddev dotenv set .ddev/.env.varnish --varnish-docker-image=varnish:$VARNISH_VERSION --varnish-varnishd-params " -p $vcl_path=/etc/varnish -f /etc/varnish/$vcl_file" | ||
|
|
||
| ddev get ddev/ddev-varnish | ||
|
|
||
| ddev config --web-environment-add HTTPCACHE_PURGE_SERVER=http://varnish | ||
| ddev config --web-environment-add HTTPCACHE_PURGE_TYPE=varnish | ||
| ddev config --web-environment-add TRUSTED_PROXIES=varnish | ||
|
|
||
| ddev restart | ||
|
adriendupuis marked this conversation as resolved.
|
||
| ddev php bin/console cache:clear | ||
| ``` | ||
|
|
||
| To use Varnish 6.0LTS, set the following variable instead: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about Varnish 5?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 5 is not officially supported anymore even if the varnish5.vcl file is still there
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, but then we have a mismatch with this part of the script: It should be unified - either we mention Varnish 5 with all info, or we skip it completely
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm about to remove it from script
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| ```bash | ||
| VARNISH_VERSION=6.0 | ||
|
adriendupuis marked this conversation as resolved.
|
||
| ``` | ||
|
|
||
| If you're using [Apache as web server](install_with_ddev.md#switch-to-apache-and-its-virtual-host), | ||
| you must set `varnish` as a trusted proxy in `.ddev/apache/apache-site.conf` before restarting DDEV: | ||
|
|
||
| ```bash | ||
| sed -i 's/#SetEnv TRUSTED_PROXIES ""/SetEnv TRUSTED_PROXIES "varnish"/' .ddev/apache/apache-site.conf | ||
|
|
||
| ddev restart | ||
| ``` | ||
|
|
||
| The Varnish server acts as the application’s primary entry point. | ||
| If you run `ddev describe`, you can see that Varnish is now the one responding to DDEV domain `.ddev.site` | ||
| while the web server still replies to `127.0.0.1` with its own ports. | ||
|
|
||
| You can see Varnish headers in HTTP responses, for example: | ||
|
|
||
| ```console | ||
| % curl -s -c cookies.txt -b cookies.txt -I https://<your-project>.ddev.site:<https-port>/ | ||
|
adriendupuis marked this conversation as resolved.
|
||
| HTTP/2 200 | ||
|
Check warning on line 102 in docs/infrastructure_and_maintenance/clustering/clustering_with_ddev.md
|
||
| server: Apache/2.4.65 (Debian) | ||
| vary: Origin,X-Editorial-Mode | ||
| via: 1.1 varnish (Varnish/7.1) | ||
| x-cache: HIT | ||
| x-cache-debug: 1 | ||
| x-cache-hits: 5 | ||
| x-cache-ttl: 87654.321 | ||
| x-debug-token: 012345 | ||
| x-debug-token-link: https://<your-project>.ddev.site:<https-port>//_profiler/012345 | ||
| x-powered-by: Ibexa Commerce v5 | ||
| x-robots-tag: noindex | ||
| x-varnish: 12345 67890 | ||
| xkey: ez-all c52 ct42 l2 pl1 p1 p2 | ||
| content-length: 45678 | ||
| ``` | ||
|
|
||
| You can see how the `web` server is responding to `varnish`: | ||
|
adriendupuis marked this conversation as resolved.
|
||
|
|
||
| ```console | ||
| % curl -s -H "Surrogate-Capability: abc=ESI/1.0" http://127.0.0.1:<http-web-port>/product-catalog | grep 'esi:include' | ||
|
adriendupuis marked this conversation as resolved.
|
||
| <esi:include src="/_fragment?_hash=… | ||
| ``` | ||
|
|
||
| To explore more the communication between the web server and Varnish, you can find other examples of requests done directly to the web server while impersonating Varnish in [Fetching user context hash](content_aware_cache.md#fetching-user-context-hash) and [Fetching HTML response](content_aware_cache.md#fetching-html-response). | ||
|
|
||
| You can use `ddev varnishlog` command to monitor Varnish logs in real time. | ||
| Due to how parameters are passed to the container, you may have to wrap some parameters in quotes twice, for example, the purge request monitoring: | ||
|
|
||
| ```bash | ||
| ddev varnishlog -q "'ReqMethod ~ PURGE.*'"; | ||
| ``` | ||
|
|
||
| For more information on topics such as available configurations, command lines, or monitoring, see [ddev/ddev-varnish README](https://github.com/ddev/ddev-varnish). | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Link again to http cache for more info how to use that with Ibexa? That's up to you
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see what to link to in the actual state of our doc. |
||
|
|
||
| ### Fastly | ||
|
|
||
| For Fastly (as for [[[= product_name_connect =]]](https://doc.ibexa.co/projects/connect/en/latest/)), the instance must be visible from Internet. | ||
|
|
||
| To use [ngrok](https://ngrok.com/) alongside [`ddev share`](https://docs.ddev.com/en/stable/users/topics/sharing/#using-ddev-share-easiest) is probably the easiest way to achieve this. | ||
|
|
||
| Be careful when making a local development instance visible from the internet. | ||
| For example: | ||
|
|
||
| - close ngrok tunnels when not needed anymore | ||
| - keep your ngrok URL private and share it only with trusted recipients | ||
| - don't use it for live demo where the URL could be seen | ||
| - don't store it on a Fastly or [[= product_name_connect =]] accounts used by external people | ||
|
|
||
| See [Configure and customize Fastly](fastly.md) for the Fastly side. | ||
|
|
||
| ## Install search engine | ||
|
|
||
| A [search engine](search_engines.md) can be added to the cluster. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add an introduction sentence hear linking to HTTP cache doc, for people unfalimiar with it