【发布时间】:2016-10-25 18:37:26
【问题描述】:
我的 nginx.conf 在本地 (OSX) 上运行,但在 prod (Ubuntu) 上抛出错误
完整文件:https://github.com/thomasdane/partywave/blob/master/nginx.conf
但相关部分是:
# 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;
}
}
在我的 Mac 上,效果很好并且输出:
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
ETag: W/"42120-1570e612108"
Expires: Tue, 01 Nov 2016 09:27:51 GMT
但是,当我在生产环境(Ubuntu 14.04)上运行完全相同的 nginx.conf 时,出现以下错误:
nginx: [emerg] "expires" directive invalid value in /etc/nginx/nginx.conf:46
如果我删除 $expires 代码,它可以在生产环境中正常工作(当然没有过期)。
我已经在谷歌上搜索了一段时间,但不知道为什么。希望有任何帮助。
【问题讨论】:
-
它们是
nginx的不同版本吗? -
@RichardSmith 是的,这就是问题所在。感谢您的帮助。