我刚刚设置了一个在 Unicorn 上运行的 Sinatra 应用程序,并通过 NGINX 的套接字提供服务。
我试图让 NGINX 在我的 nginx 配置中为我的静态资源提供服务:
upstream unicorn {
server unix:/tmp/unicorn.app.sock fail_timeout=0;
}
server {
listen 80 default;
server_name localhost;
root /home/ubuntu/app;
location ^~ /public/ {
root /home/ubuntu/app;
gzip_static on;
expires max;
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 4G;
keepalive_timeout 10;
}
但是我的 unicorn 日志仍然显示它正在提供文件
[03/Oct/2014 19:25:05] "GET /javascript/map.js HTTP/1.0" 304 - 0.0016
[03/Oct/2014 19:25:05] "GET /javascript/geopo.js HTTP/1.0" 304 - 0.0030
[03/Oct/2014 19:25:05] "GET /images/logo.png HTTP/1.0" 304 - 0.0022
等等
我错过了什么?
最佳答案
您需要明确告诉 Web 服务器通过 location
指令加载这些文件。
以下是我使用 Unicorn 让 Web 服务器加载资源的示例:
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
root /home/ubuntu/app/public;
expires max;
add_header Cache-Control public;
log_not_found off;
}
关于nginx - 使用 NGINX 为 UNICORN 服务的应用程序提供静态文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26186048/