【问题标题】:Leverage browser caching issue with Nginx利用 Nginx 的浏览器缓存问题
【发布时间】:2014-07-08 06:01:16
【问题描述】:

我有一个 rails 应用程序部署在 Amazon EC2 服务器 - Nginx & Unicorn

我必须启用浏览器缓存

这是我的 nginx.conf

的代码
upstream unicorn {
server unix:/tmp/unicorn.nqlive.sock fail_timeout=0;
}

server {
listen 80;
listen 443 ssl;
server_name xyz.com;
ssl_certificate /usr/local/nginx/conf/server.crt;
ssl_certificate_key /usr/local/nginx/conf/server.key;
root /home/ec2-user/hello/production/current/public;


location ~* \.(css|js|gif|jpe?g|png)$ {
expires 168h;
add_header Pragma public;
add_header Cache-Control "public";
}

try_files $uri/index.html $uri @unicorn;
location @unicorn {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://unicorn;
}

error_page 500 502 503 504 /500.html;
client_max_body_size 20M;
keepalive_timeout 10;
}

所有的css、图片、js都开始报403 Forbidden Error。我也尝试将权限更改为 777,但没有成功。

【问题讨论】:

  • 你必须显示完整的配置。
  • 他们在/home/ec2-user/hello/production/current/public吗?
  • 好吧,检查error.log

标签: ruby-on-rails nginx amazon-ec2 browser-cache


【解决方案1】:

将文件的所有权更改为 Nginx 用户。 Web 服务器通常不仅需要读取权限,还需要所有权。更何况 SSH 与 PEM 文件连接特别需要 600 权限才能使 PEM 文件工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-23
    • 2020-09-10
    • 2015-09-06
    • 1970-01-01
    • 2013-12-10
    • 2018-06-06
    • 1970-01-01
    • 2018-03-27
    相关资源
    最近更新 更多