I have deployed my Rails app to VPS (DigitalOcean). I have installed NGINX that will handle all my static css
, js
and html
files.
I have uploaded my project via capistrano.
When I open my page at example.com
it shows me page Welcome to NGINX. I can only access to my pages by entering example.com:8080/admin
and it does not load css
, js
and html
files.
NGINX does not detect static files, which are generated by Rails.
What did I miss? Why I my rails app is on 8080 port?
My nginx.conf
file is:
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;
}
I'm using Puma. My deploy.rb
file:
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
My config/deploy/production.rb
:
server "my.server.ip.here",
:user => "deployer",
:roles => %w(web app db)
My nginx.conf
file located on 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/*;
}
There are a lot of lines which were commented. I have just skipped them.
My var/log/nginx/error.log
has that kind of lines:
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)