我正在关注本教程在我的云服务器上部署 rails 应用程序。这是我第一次在服务器上部署 rails 项目。
当尝试从文件夹 /app/current 和用户组合启动 unicorn 或 nginx 时,出现错误:
authentication failure; logname=portfolio uid=1002 euid=0 tty=/dev/pts/0 ruser=portfolio rhost= user=portfolio
和:Could not locate Gemfile or .bundle/ directory
我当前文件夹中有 Gemfile 和 .bundle。权限是
-rw-r--r-- 1 portfolio portfolio 2214 Mar 31 06:53 Gemfile
drwxr-xr-x 2 portfolio portfolio 4096 Mar 31 06:54 .bundle
我的 nginx.conf 如下所示:
http {
include /etc/nginx/conf.d/*.conf;
}
upstream app {
# Path to Unicorn SOCK file, as defined previously
server unix:/tmp/unicorn.sock fail_timeout=0;
}
server {
listen 80;
server_name mywebsite.com www.mywebsite.com;
# Application root, as defined previously
root /var/www/portfolio/current/public;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://localhost:22/;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
}
我的 unicorn.rb 文件如下所示:
# set path to the application
app_dir = File.expand_path('../..', __FILE__)
shared_dir = "#{app_dir}/shared"
working_directory app_dir
current_path = "#{app_dir}/current"
before_exec do |server|
ENV['BUNDLE_GEMFILE'] = "#{current_path}/Gemfile"
end
# Set unicorn options
worker_processes 2
preload_app true
timeout 30
# Path for the Unicorn socket
listen "#{shared_dir}/sockets/unicorn.sock", :backlog => 64
# Set path for logging
stderr_path "#{shared_dir}/log/unicorn.stderr.log"
stdout_path "#{shared_dir}/log/unicorn.stdout.log"
# Set proccess id path
pid "#{shared_dir}/pids/unicorn.pid"