【发布时间】:2015-06-25 19:50:49
【问题描述】:
问题:
图像无法读取/写入我的 Dragonfly 数据库服务器文件结构。我可以通过所有 Ruby 模型的活动记录与我的数据库进行交互。我所有的静态资产都在工作。用户生成的图像应保存为 www.test.example.com/media/AgGdsgDGsdgsDGSGdsgsdg... 在我的远程服务器上。但是,它们会保存在从中上传的任何应用服务器上。
背景:
Ruby/Rails、Nginx、Passenger。我们正在从单服务器解决方案转向三服务器解决方案。我有 2 个应用程序服务器位于数据库服务器后面。我将 Dragonfly Gem 用于用户生成的图像和其他内容。在我们当前的单服务器设置中,所有内容都指向 localhost 并且运行良好。
10.102.66.4 是我的数据库服务器的局域网 IP。
应用服务器 NGINX.CONF:
user pete;
...
http {
passenger_pre_start http://example.com;
passenger_pre_start http://example.com:3000;
...
proxy_cache_path /home/pete/example/shared/tmp/dragonfly levels=2:2
keys_zone=dragonfly:100m inactive=30d max_size=1g;
...
server {
listen 80;
server_name example.com;
rewrite ^ https://example.com$request_uri? permanent;
}
server {
listen 443 ssl default deferred;
ssl on;
ssl_certificate /etc/ssl/example.com.crt;
ssl_certificate_key /etc/ssl/server.key;
ssl_session_cache shared:SSL:1m;
server_name example.com *.example.com;
root /home/pete/example/current/public;
passenger_enabled on;
location /media {
proxy_pass http://10.102.66.4:443;
proxy_cache dragonfly;
proxy_cache_valid 200 30d;
break;
}
}
}
数据库服务器 NGINX.CONF:
user pete;
...
http {
sendfile on;
...
keepalive_timeout 65;
types_hash_max_size 2048;
...
large_client_header_buffers 4 16k;
server {
listen 443 ssl;
ssl_certificate /etc/ssl/example.com.crt;
ssl_certificate_key /etc/ssl/server.key;
location / {
try_files $uri @app;
}
location @app {
proxy_set_header host $Host;
proxy_redirect off;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
root /home/pete/example/shared/;
}
}
}
DRAGONFLY.RB:
require 'dragonfly'
app = Dragonfly[:images]
app.configure_with(:imagemagick)
app.configure_with(:rails)
if defined?(ActiveRecord::Base)
app.define_macro(ActiveRecord::Base, :image_accessor)
app.define_macro(ActiveRecord::Base, :file_accessor)
end
我尝试了什么:
'chown -R pete:pete /home/pete/example/current/public' 并且权限看起来正确。
重启服务器/nginx/ruby/etc...
添加'large_client_header_buffers 4 16k;'到 nginx.conf
错误/日志:
Chrome 控制台:
Failed to load resource: the server responded with a status of 400 (Bad Request)
NGINX ERROR.LOG(是的..我知道它说“警告”)
2015/06/25 11:49:11 [warn] 25591#0: *345 a client request body is buffered to a temporary file /var/lib/nginx/body/0000000002, client: 173.204.167.103, server: example.com, request: "POST /offices/1-big-o/users/1-peterb HTTP/1.1", host: "test.example.com", referrer: "https://test.example.com/offices/1-big-o/users/1-peterb/edit"
NGINX ACCESS.LOG:
[25/Jun/2015:11:49:14 -0700] "GET /media/W1siZiIsIjIwMTUvMDYvMjUvMTFfNDlfMTFfNDcxXzhfYml0X21scF9vY19fX2xvY2tlX3R1bWJsZXJfYnlfbmlnaHRzaGFkZTQyNF9kNXppdmpmLmpwZyJdXQ HTTP/1.0" 400 681 "https://test.example.com/offices/1-big-o/users/1-peterb/edit" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.125 Safari/537.36
curl -k https://10.102.66.4:443
<html>
<head><title>403 Forbidden</title></head>
<hr><center>nginx/1.4.6 (Ubuntu)</center>
</body>
</html>
更新 1:
似乎不是将我的文件保存在数据库服务器上,而是将它们本地保存到我的应用服务器。文件结构是正确的...只是错误的服务器。
【问题讨论】:
-
proxy_pass 设置为什么?
-
远程服务器局域网ip
标签: ruby-on-rails ruby nginx passenger dragonfly-gem