在Puma,rails,nginx上设置一个rails应用程序一切正在运行,但nginx发送错误

我正在尝试运行一个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错误。

我应该如何继续? 似乎事情正在运行,但彪马和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 3000puma -e production -d -b unix:///tmp/web-app.sock --pidfile /tmp/puma.pid创build美洲狮进程, t似乎与nginx进行通信,但不会返回任何错误。

编辑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 ,url只是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

我已经对上面的configuration文件做了很多改变,没有任何改变。 我现在拥有了我认为是正确的configuration。 我很茫然,并希望有任何build议。

小问题:如果在同一个虚拟机上有其他用户,并且他们可能安装了nginx并且configuration不同,是否会导致问题?

StackOverflow过于讨厌“代码不正确”,所以我决定把所有的答案作为代码。

 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