Expires in nginx.conf will cause errors on Ubuntu, but no errors on OSX

My nginx.conf is using local (OSX), but it throws an error on prod (Ubuntu)

Full file: https:// github.com/thomasdane/partywave/blob/master/nginx.conf

But the relevant part is:

# Expires map
map $ sent_http_content_type $expires {
default off;
text/html 1w;
text/css 1w;
application/javascript 1w;
~image/ 1w;
}

server {
listen 80;
expires $expires;
server_name http://www.partywave.co/;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}

On my Mac, this works well, output:

< pre>curl -I localhost/images/hero.jpg
HTTP/1.1 200 OK
Se rver: nginx/1.10.1
Date: Tue, 25 Oct 2016 09:27:51 GMT
Content-Type: image/jpeg
Content-Length: 270624
Connection: keep-alive
X-Powered-By: Express
Accept-Ranges: bytes
Cache-Control: max-age=604800
Last-Modified: Fri, 09 Sep 2016 09 :57:09 GMT
ETag: W/”42120-1570e612108″
Expires: Tue, 01 Nov 2016 09:27:51 GMT

However, when I was in production (Ubuntu 14.04) When I run the exact same nginx.conf, I receive the following error:

nginx: [emerg] "expires" directive invalid value in /etc/nginx/nginx .conf:46

If I delete the $expires code, it works fine on production (not expired of course).

I have been googled for a while and can’t figure out why. Would love any help.

What version of nginx do you have in ubuntu?
If you have the default repository for 14.04, it is 1.4.6. And expires only accepts variables since 1.7.9.
You can add nginx official repo and install 1.10 from it. Semi-automatic installation:

< /p>

apt-get install -y lsb-release
LIST="/etc/apt/sources.list.d/nginx.list"; OS=`lsb_release- si | tr'[:upper:]''[:lower:]'`; RELEASE=`lsb_release -sc`; if [! -f $LIST ]; then echo -e "deb http://nginx.org/ packages/$OS/ $RELEASE nginx deb-src http://nginx.org/packages/$OS/ $RELEASE nginx"> $LIST; else echo "File $LIST exists! Check it."; fi
wget -q -O- http://nginx.org/keys/nginx_signing.key | apt-key add -
apt-get update
apt-get remove -y nginx-full nginx-common
apt-get install nginx

My nginx.conf is using local (OSX), but it throws an error on prod (Ubuntu)

< /p>

Full file: https://github.com/thomasdane/partywave/blob/master/nginx.conf

But the relevant part is:

# Expires map
map $sent_http_content_type $expires {
default off;
text/html 1w;
text/css 1w;
application/javascript 1w;
~image/ 1w;
}

server {
listen 80;
expires $expires;
server_name http://www.partywave.co/;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}

On my Mac, This works well, the output is:

curl -I localhost/images/hero.jpg
HTTP/1.1 200 OK
Server: nginx/1.10. 1
Date: Tue, 25 Oct 2016 09:27:51 GMT
Content-Type: image/jpeg
Content-Length: 270624
Connection: keep-alive
X-Powered-By: Express
Accept-Ranges: bytes
Cache-Control: max-age=604800
Last-Modified: Fri, 09 Sep 2016 09:57:09 GMT< br />ETag: W/"42120-1570e612108"
Expires: Tue, 01 Nov 2016 09:27:51 GMT

But , When I run the exact same nginx.conf on production (Ubuntu 14.04), I receive the following error:

nginx: [emerg] "expires" directive invalid value in /etc/nginx/nginx.conf:46

If I delete the $expires code, it works fine on production (of course it is not expired).

I have googled for a while Time, I can’t figure out why. Would appreciate any help.

What version of nginx do you have in ubuntu?
If you have the default repository for 14.04, it is 1.4.6. And expires only accepts variables since 1.7.9.
You can add nginx official repo and install 1.10 from it. Semi-automatic installation:

< /p>

apt-get install -y lsb-release
LIST="/etc/apt/sources.list.d/nginx.list"; OS=`lsb_release- si | tr'[:upper:]''[:lower:]'`; RELEASE=`lsb_release -sc`; if [! -f $LIST ]; then echo -e "deb http://nginx.org/ packages/$OS/ $RELEASE nginx deb-src http://nginx.org/packages/$OS/ $RELEASE nginx"> $LIST; else echo "File $LIST exists! Check it."; fi
wget -q -O- http://nginx.org/keys/nginx_signing.key | apt-key add -
apt-get update
apt-get remove -y nginx-full nginx-common
apt-get install nginx

Leave a Comment

Your email address will not be published.