Stackoverflowers。我的Rails nginx配置有问题。我正在运行Rails 3.0.12应用程序,我对nginx很新。
我似乎无法获得nginx来提供静态资产。对于/public
文件夹中的每个请求,我得到404.我发布了到目前为止我发现的nginx配置。也许我错过了什么
nginx.conf
:
user rails;
worker_processes 1;
daemon off;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 2048;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
gzip on;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_proxied any;
gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
server_names_hash_bucket_size 64;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
sites-enabled/project.conf
:
upstream project {
# fail_timeout=0 means we always retry an upstream even if it failed
# to return a good HTTP response (in case the Unicorn master nukes a
# single worker for timing out).
# for UNIX domain socket setups:
server unix:/tmp/project.socket fail_timeout=0;
}
server {
listen 80;
root /srv/www/project/current/public;
passenger_enabled on;
server_name dev.project.eu;
server_name *.dev.project.eu;
location / {
#all requests are sent to the UNIX socket
proxy_pass http://project;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
root /srv/wwww/project/current/public;
}
}
我尝试从location /
删除project.conf
块,但它没有做任何事情,资产仍然不可见。
我也知道在Rails中serve_static_assets
切换,但我宁愿让nginx服务这些资产,因为它应该这样做。
答案 0 :(得分:6)
您需要添加类似的内容(documentation on locations):
location / {
try_files $uri @ruby;
}
location @ruby {
proxy_pass http://project;
}
答案 1 :(得分:0)
我知道这个帖子已经有一年多了但我在生产中遇到了同样的问题
使它适用于我的事情正在运行
rake assets:precompile
正在开发中,并且没有注释
load 'deploy/assets'
即使我正在使用rails 4。