【发布时间】:2015-07-14 17:04:16
【问题描述】:
我已将我的 Rails 应用程序部署到 VPS (DigitalOcean)。我已经安装了 NGINX,它将处理我所有的静态 css、js 和 html 文件。
我已经通过 capistrano 上传了我的项目。
当我在example.com 打开我的页面时,它会显示页面Welcome to NGINX。我只能通过输入example.com:8080/admin 来访问我的页面,它不会加载css、js 和html 文件。
NGINX 不检测由 Rails 生成的静态文件。
我错过了什么?为什么我的 rails 应用在 8080 端口上?
我的nginx.conf 文件是:
upstream puma {
server unix:///var/www/newsapp/shared/tmp/sockets/newsapp-puma.sock;
}
server {
listen 80 default_server deferred;
# server_name example.com;
root /var/www/newsapp/current/public;
access_log /var/www/newsapp/current/log/nginx.access.log;
error_log /var/www/newsapp/current/log/nginx.error.log info;
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
try_files $uri/index.html $uri @puma;
location @puma {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://puma;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 10M;
keepalive_timeout 10;
}
我正在使用 彪马。我的deploy.rb 文件:
set :application, 'newsapp'
set :repo_url, 'https://example@bitbucket.org/example.git'
set :linked_dirs, %w(
bin log vendor/bundle public/system
tmp/pids tmp/cache tmp/sockets
)
set :puma_bind, "unix:///var/www/newsapp/shared/tmp/sockets/newsapp-puma.sock"
set :puma_state, "/var/www/newsapp/shared/tmp/pids/puma.state"
set :puma_pid, "/var/www/newsapp/shared/tmp/pids/puma.pid"
set :puma_access_log, "/var/www/newsapp/shared/log/puma.error.log"
set :puma_error_log, "/var/www/newsapp/shared/log/puma.access.log"
namespace :deploy do
after :restart, :clear_cache do
on roles(:web), in: :groups, limit: 3, wait: 10 do
# Here we can do anything such as:
# within release_path do
# execute :rake, 'cache:clear'
# end
end
end
end
我的config/deploy/production.rb:
server "my.server.ip.here",
:user => "deployer",
:roles => %w(web app db)
我的 nginx.conf 文件位于 VPS /etc/nginx:
user www-data;
worker_processes 4;
pid /run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
gzip_disable "msie6";
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
有很多行被评论。我只是跳过了它们。
我的var/log/nginx/error.log 有这样的台词:
2015/07/12 13:25:08 [emerg] 12215#0: open() "/var/www/newsapp/newsapp/current/log/nginx.access.log" failed (2: No such file or directory)
【问题讨论】:
-
你也能展示一下你的 puma 配置吗?
-
您通过套接字而不是端口访问 Puma。似乎您有多个 Nginx 服务器块,显示它侦听的端口超过 80。请显示整个 Nginx 配置并确保 error_log 为空
-
@mikhailov 这是我在 Rails 项目中的
nginx.conf文件。您的意思是位于我的 VPS 中的配置? -
@QQQ 是的,我们说服务器
-
@mikhailov 更新了我的问题
标签: ruby-on-rails nginx capistrano puma