'Reverse proxy returned invalid status code' when trying to programmatically clear the HTTP cache

The response code I am getting is a 405 from NGINX. This happens to me when running bin / console sw: theme: cache: generate it to clear the HTTP cache. It seems this is due to Shopware trying to send a BAN request and the server rejecting this. It is important to note that I am getting this error when using Varnish or any reverse proxy. Shopware is trying to send the BAN request as it can not find the httpcache service in the service container. Looking at services.xml files I can not see any entry for this.

Has anyone had a similar issue to this when using Shopware with no reverse proxy?

The reason nginx is rejecting the BAN and returning 405 is explained in this PR - would you be able to independently verify the solution and reply in the github issue or here if this helps you?

If you get a 405 from varnish, the reason should be a different one, and the requester IP not among the allowed purgers, see the varnish setup

Per default no proxyurl is defined, and as you point out, in a commandline context, the httpcache service is not present and the BAN request will always be executed (see getProxyUrl() fallback).

For nginx to then forward the BAN request to fastcgi, the proposed rewrite is a solution - and the request will go through if the origin IP is among the purge_allowed_ips (per default the ip v4/v6 loopback addresses).