我正在尝试运行rails应用。我按照以下说明操作:http://luugiathuy.com/2014/11/setup-nginx-puma-on-ubuntu/以设置服务器。
但是,当我走到尽头时,具体来说:puma -e production -d -b unix:///tmp/app_name.sock --pidfile /tmp/puma.pid
运行它后我得到了答复:
Puma starting in single mode...
* Version 2.16.0 (ruby 2.1.7-p400), codename: Midwinter Nights Trance
* Min threads: 0, max threads: 16
* Environment: production
* Daemonizing...
外部IP只是保持返回nginx错误:
We're sorry, but something went wrong.
If you are the application owner check the logs for more information.
所以,在其他地方寻找,我试过:
RACK_ENV=production bundle exec puma -p 3000
而且,这似乎做得更多,我得到了:
Puma starting in single mode...
* Version 2.15.3 (ruby 2.1.7-p400), codename: Autumn Arbor Airbrush
* Min threads: 0, max threads: 16
* Environment: production
Rails Error: Unable to access log file. Please ensure that /home/myusername/myappname/log/production.log exists and is writable (ie, make it writable for user and group: chmod 0664 /home/myusername/myappname/log/production.log). The log level has bee
n raised to WARN and the output directed to STDERR until the problem is fixed.
** [Bugsnag] Bugsnag exception handler 3.0.0 ready, api_key=#####################
* Listening on tcp://0.0.0.0:3000
Use Ctrl-C to stop
但是外部网页返回了相同的nginx错误。
我该怎么办?似乎事情正在运行,但是puma和nginx只是不说话?
编辑1
I did: `sudo chmod -R 0777 /home/myunsername/appname/log/`
Then:
$RACK_ENV=production bundle exec puma -p 3000
而且,现在输出低于,外部IP的nginx响应保持不变。
Puma starting in single mode...
* Version 2.15.3 (ruby 2.1.7-p400), codename: Autumn Arbor Airbrush
* Min threads: 0, max threads: 16
* Environment: production
* Listening on tcp://0.0.0.0:3000
Use Ctrl-C to stop
现在,两种方法:RACK_ENV=production bundle exec puma -p 3000
和puma -e production -d -b unix:///tmp/web-app.sock --pidfile /tmp/puma.pid
都会创建似乎与nginx无法通信但不会返回任何错误的puma进程。
编辑2 检查日志
我跑了:
cat log/production.log
然后又回来了:
I, [2016-02-02T##:##:##.###### #28802] INFO -- : ** [Bugsnag] Bugsnag exception handler 3.0.0 ready, api_key=####################
编辑2.5 检查更多日志 我跑了:
tail -f /var/log/nginx/error.log
然后又回来了:
2016/02/02 11:09:52 [emerg] 28220#0: unknown directive "tream" in /etc/nginx/sites-enabled/web-appname.com:1
2016/02/02 11:10:26 [emerg] 28273#0: unknown directive "tream" in /etc/nginx/sites-enabled/web-appname.com:1
这些错误是在我的文件丢失前3个字符之前引起的,此错误已被修复。总结:我在上面列出的日志中似乎没有任何错误给我任何提示。
编辑3
我的猜测目前是我错误地设置了我的/etc/nginx/sites-available/myapp.com文件。以下是我使用过的所有命名。
目前它被命名为: web-app.com ,网址只是IP地址,让我们说 https://104.199.155.166/ 。我的应用程序位于名为 web-app
的文件夹中upstream web-app {
server unix:///tmp/web-app.sock;
}
server {
listen 80;
server_name web-app; # change to match your URL
root /home/myusername/web-app/public; # change to match your rails app public folder
location / {
proxy_pass http://web-app; # match the name of upstream directive which is defined in line 1
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
}
location ~* ^/assets/ {
# Per RFC2616 - 1 year maximum expiry
expires 1y;
add_header Cache-Control public;
# Some browsers still send conditional-GET requests if there's a
# Last-Modified header or an ETag header even if they haven't
# reached the expiry date sent in the Expires header.
add_header Last-Modified "";
add_header ETag "";
break;
}
}
编辑4
我对上面的配置文件做了很多更改,而我所做的一切都没有改变。我目前在我认为是正确的配置。我很茫然,不胜感激任何建议。
小问题:如果同一个虚拟机上有其他用户,并且他们可能安装了nginx并进行了不同的配置,是否会导致问题?
答案 0 :(得分:0)
StackOverflow太烦人了#34;代码没有被正确认可"所以我决定将所有答案都作为代码。
You have to create config/puma.rb manually. I recommend reading DigitalOcean's article:
["How To Deploy a Rails App with Puma and Nginx on Ubuntu 14.04"][1]
I'll paste the puma.rb from the article:
# config/puma.rb
# Change to match your CPU core count
workers 2
# Min and Max threads per worker
threads 1, 6
app_dir = File.expand_path("../..", __FILE__)
shared_dir = "#{app_dir}/shared"
# Default to production
rails_env = ENV['RAILS_ENV'] || "production"
environment rails_env
# Set up socket location
# bind "unix://#{shared_dir}/sockets/puma.sock"
# in your case
bind "unix:///tmp/web-app.sock"
# Logging
stdout_redirect "#{shared_dir}/log/puma.stdout.log", "#shared_dir}/log/puma.stderr.log", true
# Set master PID and state locations
pidfile "#{shared_dir}/pids/puma.pid"
state_path "#{shared_dir}/pids/puma.state"
activate_control_app
on_worker_boot do
require "active_record"
ActiveRecord::Base.connection.disconnect! rescue ActiveRecord::ConnectionNotEstablished
ActiveRecord::Base.establish_connection(YAML.load_file("#{app_dir}/config/database.yml")[rails_env])
end
Detail: after setting bind [...] you can just execute
$ bundle exec puma RAILS_ENV=production
Make sure that the directory shared exists and, within it, folders log and pids. Chmod them, otherwise, You'll face permission issues.
Another thing: can you show your nginx.conf file? If the user set in nginx.conf has no "rights" to read your app, You'll (also) face permission issues.
Tip: If you have problems with the empty folders from shared (log and pids) and git, put a .keep (empty file) inside both of them.
Another tip: you can set server_name (nginx directive) as _ (yes, an underscore) or localhost if you do not have a domain.
Almost forget: check if your vm has http and https traffic enabled.
[1]: https://www.digitalocean.com/community/tutorials/how-to-deploy-a-rails-app-with-puma-and-nginx-on-ubuntu-14-04