hide/strip set cookies on static files and howto use alias

Francis Daly francis at daoine.org
Tue Apr 5 07:41:56 UTC 2016

On Mon, Apr 04, 2016 at 12:29:32PM -0400, JoakimR wrote:

Hi there,

> I have a few questions about how do I configure it.

It's worth making sure that you are aware how nginx works, which is
(very briefly and roughly):

* one request is handled in one location{}
* only the configuration in, or inherited into, that location matters
* inheritance is typically by replacement, or not at all
* directives from the "rewrite" module can interfere with the above
* documentation for "location" is at http://nginx.org/r/location

> First question:
> How do I strip the "Set-Cookie" header from all static files like css and
> jpg? I know i can setup a reverse proxy and use "proxy_hide_header
> Set-Cookie", but seems like foolish to make yet another host, just to
> reverse to your self and add a few hundred msec to the request.

Where does the "Set-Cookie" header come from? Default nginx does not
add it.

Can you create a small configuration which shows the problem?

Copy-paste the configuration and a "curl -v" request and response to
show the Set-Cookie header; that should make it more obvious what needs
to be fixed.

> Second question:
> I'm trying to make an alias to hide a folder in the lookup to the subfolder,
> the structure is:
> /var/www/domain.tld/media/ads
> /var/www/domain.tld/media/galleries
> /var/www/domain.tld/media/misc
> /var/www/domain.tld/media/thumbs
> making the url like this /media/thumbs/5 subfolders/image-file
> how do i change that into /thumbs/5 subfolders/image-file

For anything involving "root" or "alias", the questions to consider are:

* what file on your filesystem do you wish to fetch?

* what url do you wish to use, to fetch that file?

And just in case it is not immediately obvious from those answers:

* what is the intended mapping between url and filename?

With that information, it may become clear what "root" or "alias"
directive to use in the "location" that handles the request.

For the above, I suspect that "root /var/www/domain.tld/media;" may be
what you want, in the location{} that handles these requests.

> I have tried with both alias and root but both returns a 404

What does the error log show?

Usually it shows the request, and the filename attempted, for a 404. That
may give a hint at what configuration should be used.

What request did you make? What location{} did you put your root or
alias directive in?

> Third question: 
> [error] 9178#9178: *13452 upstream timed out (110: Connection timed out)
> while reading response header from upstream, client: upstream:
> "fastcgi://unix:/var/run/php-fpm.sock", host:
> have a lot of those, any suggestions?

Either: ask your fastcgi server why it is slow to respond
(check its logs); or ask nginx to wait longer before giving up

These are the "location" definitions that you show:

>     location / {
> 		location /thumbs/ {
> 		location /admin/ {
> 		location ~ \.mp4$ {
> 		location ~ \.flv$ {
>     location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
>     location = /50x.html {
>     location ~ \.php$ {
>     location ~ /\.ht {

For each test request that you make, which location block have you
configured nginx to use to handle it? Is that the one that you want
nginx to use to handle it?

Good luck with it,

Francis Daly        francis at daoine.org

More information about the nginx mailing list