我正在关注DigitalOcean的这个(https://www.digitalocean.com/community/tutorials/how-to-use-the-ruby-on-rails-one-click-application-on-digitalocean)教程。我已经设法设置了所有内容,但是当我访问服务器IP时,我仍然收到502 Bad Gateway错误。所以,我挖了一下日志,发现在连接到上游时发生了"(111:拒绝连接)"在nginx / error.log文件中。之后我跑了
systemctl status unicorn
我得到以下内容:
● unicorn.service - DigitalOcean Rails One-Click Application
Loaded: loaded (/etc/systemd/system/unicorn.service; enabled; vendor preset: enabled)
Active: activating (auto-restart) (Result: exit-code) since Sat 2017-08-05 01:52:18 UTC; 8s ago
Process: 22871 ExecStart=/bin/bash /home/rails/project/.unicorn.sh (code=exited, status=1/FAILURE)
Main PID: 22871 (code=exited, status=1/FAILURE)
Aug 05 01:52:18 paxsafe systemd[1]: unicorn.service: Main process exited, code=exited, status=1/FAILURE
Aug 05 01:52:18 paxsafe systemd[1]: unicorn.service: Unit entered failed state.
Aug 05 01:52:18 paxsafe systemd[1]: unicorn.service: Failed with result 'exit-code'.
.unicorn.sh文件中的代码:
#!/bin/bash
# This file is meant to be executed via systemd.
source /usr/local/rvm/scripts/rvm
source /etc/profile.d/rvm.sh
export ruby_ver=$(rvm list default string)
export CONFIGURED=yes
export TIMEOUT= 50
export APP_ROOT=/home/rails/project
export RAILS_ENV="production"
export GEM_HOME="/home/rails/project/vendor/bundle"
export GEM_PATH="/home/rails/project/vendor/bundle:/usr/local/rvm/gems/${ruby_ver}:/usr/local/rvm/gems/${ruby_ver}@global"
export PATH="/home/rails/project/vendor/bundle/bin:/usr/local/rvm/gems/
${ruby_ver}/bin:${PATH}"
export SECRET_KEY_BASE=[random_secret]
export APP_DATABASE_PASSWORD=[random_db_password]
# Execute the unicorn process
/home/rails/project/vendor/bundle/ruby/2.4.0/bin/unicorn \
-c /etc/unicorn.conf -E production --debug
/etc/unicorn.conf文件:
listen "unix:/var/run/unicorn.project.sock"
worker_processes 4
user "rails"
working_directory "/home/rails/project"
pid "/var/run/unicorn.project.pid"
stderr_path "/var/log/unicorn/unicorn.error.log"
stdout_path "/var/log/unicorn/unicorn.info.log"
/ etc / default / unicorn file:
CONFIGURED=yes
TIMEOUT=60
APP_ROOT=/home/rails/project
CONFIG_RB=/etc/unicorn.conf
PID=/var/run/unicorn.project.pid
RAILS_ENV="production"
UNICORN_OPTS="-D -c $CONFIG_RB -E $RAILS_ENV"
PATH=/usr/local/rvm/rubies/ruby-2.4.0/bin:/usr/local/sbin:/usr/bin:/bin:/sbin:/usr/local/rvm/bin:/usr/local/rvm/gems/ruby-2.4.0@global/bin:/usr/local$
export GEM_HOME=/usr/local/rvm/gems/ruby-2.4.0
export GEM_PATH=/usr/local/rvm/gems/ruby-2.4.0:/usr/local/rvm/gems/ruby-2.4.0@global
DAEMON=/usr/local/rvm/gems/ruby-2.4.0/bin/unicorn
export SECRET_KEY_BASE=[random_secret]$
export APP_DATABASE_PASSWORD=[random_db_password]
的/ etc / nginx的/ /导轨启用位点-
upstream app_server {
server unix:/var/run/unicorn.project.sock fail_timeout=0;
}
server {
listen 80;
root /home/rails/project/public;
server_name _;
index index.htm index.html;
location / {
try_files $uri/index.html $uri.html $uri @app;
}
location ~* ^.+\.(jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|mp3|flv|mpeg|avi)$ {
try_files $uri @app;
}
location @app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app_server;
}
}