ngx_pagespeed removes header/cookies that are set by ngx-lua

135 views
Skip to first unread message

Rene Molenaar

unread,
Jan 4, 2018, 4:32:26 AM1/4/18
to ngx-pagespeed-discuss
Hi all,

I am running into an issue with ngx_pagespeed and a lua script here. We use the nginx integration of shieldsquare.com:


Which uses a lua script in the location block that sets some cookies:

location {
access_by_lua_file  /etc/nginx/lua/nginx_ss.lua; #set relative path

Without ngx_pagespeed, I see the _uzma cookies:

HTTP/1.1 200 OK
Date: Thu, 04 Jan 2018 08:53:39 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
Server: nginx
Vary: Accept-Encoding
Set-Cookie: __uzma=a052fe22-348a-4a9e-9b1f-64c5be11d1ab; path=/; Expires=Sun, 02-Jan-28 08:53:39 GMT
Set-Cookie: __uzmb=1515056019; path=/
; Expires=Sun, 02-Jan-28 08:53:39 GMT
Set-Cookie: __uzmc=996581066665; path=/; Expires=Sun, 02-Jan-28 08:53:39 GMT
Set-Cookie: uzdbm_a=9ffa96da-b27d-39be-e442-330fd50aecee; path=/

Set-Cookie: __uzmd=1515056019; path=
/; Expires=Sun, 02-Jan-28 08:53:39 GMT
Set-Cookie: PHPSESSID=5etcd60m42aq1bgr913mko8hv6; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Set-Cookie: wpfront-notification-bar-landingpage=1
Link: <https://shieldsquare.test.local/wp-json/>; rel="https://api.w.org/"
Link: <https://shieldsquare.test.local/>; rel=shortlink
X
-Proxy-Cache: HIT

Once I enable ngx_pagespeed, they are gone:

HTTP/1.1 200 OK
Date: Thu, 04 Jan 2018 09:11:53 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
Server: nginx
Vary: Accept-Encoding
Set-Cookie: PHPSESSID=5etcd60m42aq1bgr913mko8hv6; path=/
Pragma: no-cache
Set-Cookie: wpfront-notification-bar-landingpage=1
Link: <https:/
/shieldsquare.test.local/wp-json/>; rel="https://api.w.org/"
Link: <https://shieldsquare.test.local/>; rel=shortlink
X
-Proxy-Cache: HIT
X
-Page-Speed: Powered By Pagespeed
Cache-Control: max-age=0, no-cache, no-store, must-revalidate

These are the versions I am using:
  • nginx version: nginx/1.12.1
  • ngx_pagespeed-1.12.34.3-stable
  • lua-nginx-module-0.10.12rc1
I ran into this post which has a similar issue:


I tried setting pagespeed ModifyCachingHeaders off; but it didn't make a difference.

Any idea how to solve this? :) Thanks!

Rene

Otto van der Schaaf

unread,
Jan 4, 2018, 8:41:26 AM1/4/18
to ngx-pagesp...@googlegroups.com
I'm not sure, but I suspect this may have something to do with module ordering.
Is ngx_pagespeed configured to run after the lua plugin?

--
You received this message because you are subscribed to the Google Groups "ngx-pagespeed-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ngx-pagespeed-di...@googlegroups.com.
Visit this group at https://groups.google.com/group/ngx-pagespeed-discuss.
For more options, visit https://groups.google.com/d/optout.

Rene Molenaar

unread,
Jan 4, 2018, 8:53:07 AM1/4/18
to ngx-pagespeed-discuss
Hi Otto,

I didn't realize this before but right now, I compiled it like this:

                        --add-module=$(MODULESDIR)/ngx_pagespeed-1.12.34.3-stable \
                        --add-module=$(MODULESDIR)/lua-nginx-module-0.10.12rc1 \
                        --add-module=$(MODULESDIR)/ngx_devel_kit-0.3.0 \

Should I try moving ngx_pagespeed to the bottom?


Op donderdag 4 januari 2018 14:41:26 UTC+1 schreef Otto van der Schaaf:
To unsubscribe from this group and stop receiving emails from it, send an email to ngx-pagespeed-discuss+unsub...@googlegroups.com.

Rene Molenaar

unread,
Jan 4, 2018, 2:16:47 PM1/4/18
to ngx-pagespeed-discuss
Quick update:

I decided to test the order of modules to see if it would make a difference. First I tried this:

--add-module=$(MODULESDIR)/lua-nginx-module-0.10.12rc1 \
--add-module=$(MODULESDIR)/ngx_devel_kit-0.3.0 \
--add-module=$(MODULESDIR)/ngx_pagespeed-1.12.34.3-stable \

And tried running ngx_pagespeed as a dynamic module:

--add-module=$(MODULESDIR)/ngx_pagespeed-1.12.34.3-stable \

Unfortunately, the result is the same...when ngx_pagespeed is enabled, my cookies are gone.

Anything else I can try?

Op donderdag 4 januari 2018 14:53:07 UTC+1 schreef Rene Molenaar:

Otto van der Schaaf

unread,
Jan 6, 2018, 5:50:08 AM1/6/18
to ngx-pagesp...@googlegroups.com
Looking into this, I think that for your setup to work  https://github.com/pagespeed/ngx_pagespeed/issues/1154 would need fixing.
And then you could set the (experimental) flag POSITION_AUX=true when building, to get ngx_pagespeed to position itself
in the module list the way you need. 

Otto

To unsubscribe from this group and stop receiving emails from it, send an email to ngx-pagespeed-di...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "ngx-pagespeed-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ngx-pagespeed-di...@googlegroups.com.

Rene Molenaar

unread,
Jan 6, 2018, 7:24:32 AM1/6/18
to ngx-pagespeed-discuss
Hmm I guess I'm out of luck then. Nothing else I can try? Just wait and hope for this to get fixed sometime? :)

Op zaterdag 6 januari 2018 11:50:08 UTC+1 schreef Otto van der Schaaf:
To unsubscribe from this group and stop receiving emails from it, send an email to ngx-pagespeed-discuss+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "ngx-pagespeed-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ngx-pagespeed-discuss+unsub...@googlegroups.com.

Otto van der Schaaf

unread,
Jan 6, 2018, 9:57:44 AM1/6/18
to ngx-pagesp...@googlegroups.com
I dug into it some more, one thing you could try:
run "export POSITION_AUX=true" and subsequently ./configure, build  ngx_pagespeed plus the lua module as dynamic modules.
This should allow you to control the order in which these modules run via nginx.conf. 

I have not tried, but far as I can tell the POSITION_AUX flag should still work correctly for dynamic modules.

Hope that helps!

Otto

To unsubscribe from this group and stop receiving emails from it, send an email to ngx-pagespeed-di...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "ngx-pagespeed-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ngx-pagespeed-di...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "ngx-pagespeed-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ngx-pagespeed-di...@googlegroups.com.

Rene Molenaar

unread,
Jan 11, 2018, 9:47:59 AM1/11/18
to ngx-pagespeed-discuss
Hi Otto,

Thanks for your reply. I compiled ngx_pagespeed and ngx_lua as dynamic modules but no matter what I tried, when ngx_pagespeed is enabled, I can't get LUA to set cookies.

In case someone else runs into this, I solved it with a workaround. Since nginx and ngx_lua share variables, I did something like this:

Added a line in my vhost config to set an empty cookie. This is needed because ngx_lua can read/write nginx variables but it can't create new nginx variables:

set $cookie_uzm_a '';

Then in ngx_lua, don't do this:

ngx.header['Set-Cookie'] = cookie_uzm_a;

But set the variable we created in nginx:

ngx.var.cookie_uzm_a = cookie_uzm_a

And then let nginx set the header:

add_header Set-Cookie $cookie_uzm_a;

This solves it for me, maybe it's useful for someone else...

Rene

Op zaterdag 6 januari 2018 15:57:44 UTC+1 schreef Otto van der Schaaf:
To unsubscribe from this group and stop receiving emails from it, send an email to ngx-pagespeed-discuss+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "ngx-pagespeed-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ngx-pagespeed-discuss+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "ngx-pagespeed-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ngx-pagespeed-discuss+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages