Question

Hi I am learning how to deploy rails application in VPS, I have followed https://coderwall.com/p/yz8cha this tutorial, and everything worked well, I got some errors and corrected them by searching the net, and all works correctly capistrano deploys the files and folders to VPS and if I am changing any code then after type cap deploy it will changed in VPS also, everything works fine there is no error shown in terminal, But the problem is the nginx server is not running (at initial stage it shows its index page -welcome to nginx), I dont know where may be ther problem occurs and what I have to do any help will be appreciated ,,I am using rails 4.1.4, ruby 2.1.2, capistrano (2.15.5) if its matters..

I dont know which code has to be shown here If you want to see any code I am eager to show you....This is my nginx.conf file

upstream unicorn {
  server unix:/tmp/unicorn.projectname.sock fail_timeout=0;
}

server {
    listen 80 default_server deferred;
  # server_name example.com;
  root /home/administrator/apps/testvps/current/public;

  location ^~ /assets/ {
    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 20M;
   keepalive_timeout 10;
 }

This is the error I got while nginx -t in VPS terminal

nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log"            failed     (13: Permission denied)
2014/08/01 15:40:35 [warn] 5682#0: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:1
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
2014/08/01 15:40:35 [emerg] 5682#0: open() "/run/nginx.pid" failed (13: Permission denied)
nginx: configuration file /etc/nginx/nginx.conf test failed
Was it helpful?

Solution

As per error shown by nginx -t, user don't have permission to write into nginx log files.

Try running nginx -t as root user sudo nginx -t, if still it shows permission error then try updating permissions:

sudo chown -R www-data:www-data /var/log/nginx;
sudo chmod -R 755 /var/log/nginx;

Edit:

As per our discussion, your nginx configuration is successfully set. Now you are seeing blank page while accessing the app.

You need to add root to your routes.rb file. Rails 4 don't have public/index.html file . So, you are seeing blank page. After setting root you will be able to see your home page.

Your further doubt:

so this is nginx.conf file root /home/administrator/apps/testvps/current/public;

shall i change like this: root /home/administrator/apps/testvps/current;

No, nginx should look to your public directory of the app. it's rails responsibility to navigate the request to root_path as mentioned in routes.rb

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top