Ruby on rails Foreman无法启动Nginx,但我可以手动启动。为什么?
我目前运行的是staging(Ubuntu),一旦我开始工作,我将切换到使用upstart My Procfile.staging如下所示:Ruby on rails Foreman无法启动Nginx,但我可以手动启动。为什么?,ruby-on-rails,ruby,process,nginx,foreman,Ruby On Rails,Ruby,Process,Nginx,Foreman,我目前运行的是staging(Ubuntu),一旦我开始工作,我将切换到使用upstart My Procfile.staging如下所示: nginx: sudo service nginx start unicorn: bundle exec unicorn -c ./config/unicorn.rb redis: bundle exec redis-server sidekiq: bundle exec sidekiq -v -C ./config/sidekiq.yml 我可以使用以
nginx: sudo service nginx start
unicorn: bundle exec unicorn -c ./config/unicorn.rb
redis: bundle exec redis-server
sidekiq: bundle exec sidekiq -v -C ./config/sidekiq.yml
我可以使用以下方法成功启动nginx:
$ sudo service nginx start
但是,当我运行$foreman start
时,当其他三个进程成功启动时,nginx不会:
11:15:46 nginx.1 | started with pid 15966
11:15:46 unicorn.1 | started with pid 15968
11:15:46 redis.1 | started with pid 15971
11:15:46 sidekiq.1 | started with pid 15974
11:15:46 nginx.1 | Starting nginx: nginx.
11:15:46 nginx.1 | exited with code 0
11:15:46 system | sending SIGTERM to all processes
SIGTERM received
11:15:46 unicorn.1 | terminated by SIGTERM
11:15:46 redis.1 | terminated by SIGTERM
11:15:46 sidekiq.1 | terminated by SIGTERM
那么,当由Foreman启动时,为什么nginx不启动呢?这是您的程序文件中的一个问题
nginx
命令不能在foreman
内部使用sudo
,因为它将始终请求密码
,然后它将失败。这就是为什么您没有启动nginx
,并且日志是空的
如果您真的需要在procfile中使用sudo,您可以使用如下内容:
sudo_app: echo "sudo_password" | sudo -S app_command
nginx: echo "sudo_password" | sudo -S service nginx start
我真的不推荐。另一个选项是调用sudo工头启动
要了解更多信息,请查看此项,这正是您想要解决的问题
如果对您有效,请随时通知我。您应该能够为本地用户添加无需密码的sudo访问,以允许管理此服务。这可能是一个很大的安全漏洞,但如果将可以运行的命令列为白名单,则可以显著降低风险。我建议不要为services命令和要编写脚本的任何其他内容添加密码sudoers条目: /etc/sudoers:
your_user_name ALL = (ALL) NOPASSWD: /usr/sbin/service
如果您对此不满意,另一种选择是直接运行nginx,而不是通过服务管理器:
nginx: /usr/sbin/nginx -c /path/to/nginx.conf
查看您的nginx日志,“退出代码为0”可能意味着很多事情。通常可以在/var/log中找到日志/nginx@TanelSuurhans谢谢你的建议。不幸的是,有两个日志,但是/var/log/nginx/access.log和/var/log/nginx/error.log都是空的。如果改为执行
$sudo foreman start
会发生什么?