easyengine icon indicating copy to clipboard operation
easyengine copied to clipboard

redis-php-7.conf sets $skip_cache 0; on POST requests?

Open khromov opened this issue 10 years ago • 10 comments

Relevant line from redis-php7-conf:

# POST requests and URL with a query string should always go to php
if ($request_method = POST) {
  set $skip_cache 0;
}

Shouldn't $skip_cache 0 be $skip_cache 1 ?

Please attach the output of following command when open a new support request.

  • [x] lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.4 LTS
Release:        14.04
Codename:       trusty
  • [x] ee -v
EasyEngine v3.6.1
  • [x] ee info

NGINX (1.10.0):

user                             www-data
worker_processes                 auto
worker_connections               4096
keepalive_timeout                30
fastcgi_read_timeout             300
client_max_body_size             100m
allow                            127.0.0.1

PHP (5.6.22-2):

user
expose_php                       Off
memory_limit                     128M
post_max_size                    100M
upload_max_filesize              100M
max_execution_time               300

Information about www.conf
ping.path                        /ping
pm.status_path                   /status
process_manager                  ondemand
pm.max_requests                  500
pm.max_children                  100
pm.start_servers                 20
pm.min_spare_servers             10
pm.max_spare_servers             30
request_terminate_timeout        300
xdebug.profiler_enable_trigger   off
listen                           127.0.0.1:9000

Information about debug.conf
ping.path                        /ping
pm.status_path                   /status
process_manager                  ondemand
pm.max_requests                  500
pm.max_children                  100
pm.start_servers                 20
pm.min_spare_servers             10
pm.max_spare_servers             30
request_terminate_timeout        300
xdebug.profiler_enable_trigger   on
listen                           127.0.0.1:9001

MySQL (10.1.14-MariaDB) on localhost:

port                             3306
wait_timeout                     600
interactive_timeout              28800
max_used_connections             2
datadir                          /var/lib/mysql/
socket                           /var/run/mysqld/mysqld.sock
my.cnf [PATH]                    /etc/mysql/conf.d/my.cnf
  • [x] wp --allow-root --info
PHP binary:     /usr/bin/php7.0
PHP version:    7.0.7-2+donate.sury.org~trusty+1
php.ini used:   /etc/php/7.0/cli/php.ini
WP-CLI root dir:        phar://wp-cli.phar
WP-CLI packages dir:    /root/.wp-cli/packages/
WP-CLI global config:
WP-CLI project config:
WP-CLI version: 0.23.0

khromov avatar May 29 '16 23:05 khromov

Hi @khromov Thanks for pointing out the issue. We will fix it on next release.

iam404 avatar May 30 '16 06:05 iam404

@khromov @iam404 srcache-nginx-module by default does not cache the POST request so keeping above config unchanged will not harm. Refer : https://github.com/openresty/srcache-nginx-module#srcache_methods

harshadyeola avatar May 31 '16 07:05 harshadyeola

@harshadyeola In that case, may I suggest to either remove that directive from redis-php7.conf altogether, or set it to $skip_cache 1; to avoid confusion?

khromov avatar May 31 '16 07:05 khromov

We will do set $skip_cache 1;

Reason

Fasctcgi - http://nginx.org/en/docs/http/ngx_http_fastcgi_module.html#fastcgi_cache_methods also does not cache HTTP POST requests by default. In fact by default HTTP POST and Query String shall not be cached.

But if anything changes in future, we can avoid surprises by explicitly telling not to cache POST request.

Also, at some point, I want to refactor nginx config files so that all rules like below can we defined in one place and used with different caching mechanism.

# POST requests and URL with a query string should always go to php
if ($request_method = POST) {
  set $skip_cache 0;
}

This is in line with DRY also - https://en.wikipedia.org/wiki/Don%27t_repeat_yourself

And keeping in line with DRY, if we remove above 3 lines at some point, they will be removed from all config files including fastcgi.

So for now, we will add set $skip_cache 1;

rahul286 avatar May 31 '16 08:05 rahul286

@rahul286 thanks for nice explaination 👍

harshadyeola avatar May 31 '16 08:05 harshadyeola

Let's say I DO want to cache POST requests. Is there any way to do this?

Thanks.

frederichoule avatar Jun 16 '16 16:06 frederichoule

@frederichoule POST requests are by definition submissions to post information, so caching those would be a really bad idea. Just convert any POST call you have into a GET call.

khromov avatar Jun 16 '16 16:06 khromov

@khromov I have a website that doesn't need any kind of POST except on a specific URL, so I rather "cache" those requests to limit possible DDoS attacks that would trigger PHP on every request because it is not cached.

If that can help anybody, adding this line to your nginx.conf will do the job. And make sure you set your $skip_cache variable according to your requirements.

srcache_methods POST PUT DELETE;

frederichoule avatar Jun 16 '16 16:06 frederichoule

It's a shame (and a little frustrating) this was rejected at the time: https://github.com/EasyEngine/easyengine/pull/678 Anyway, glad it made it in eventually.

kymcarlsson avatar Jun 23 '16 21:06 kymcarlsson

@kymcarlsson I admit it was a mistake on behalf of core team to reject #678 I apologise for frustation it caused to you.

rahul286 avatar Jun 24 '16 19:06 rahul286