本文介绍了在puma,rails,nginx上设置Rails应用程序一切都在运行,但是nginx发送错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我正在尝试运行Rails应用程序.我遵循了以下说明: http://luugiathuy.com/2014/11 /setup-nginx-puma-on-ubuntu/来设置服务器.

I am trying to run a rails app. I followed these instructions: http://luugiathuy.com/2014/11/setup-nginx-puma-on-ubuntu/ to set up a server.

但是,当我结束时,特别是:puma -e production -d -b unix:///tmp/app_name.sock --pidfile /tmp/puma.pid运行它时,我得到了响应:

But, when I got to the end, specifically: puma -e production -d -b unix:///tmp/app_name.sock --pidfile /tmp/puma.pid Upon running it I got the response:

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错误:

The external IP just kept returning the nginx error:

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

So, looking elsewhere, I tried:RACK_ENV=production bundle exec puma -p 3000

而且,这样做似乎还更多,

And, it seemed that this did more, I got:

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错误.

But the external web page returned the same nginx error.

我应该如何进行?似乎一切都在运转,但puma和nginx却不在说话?

How should I proceed? It seems that things are running but puma and nginx just are not talking?

编辑1

I did:  `sudo chmod -R 0777 /home/myunsername/appname/log/`

Then:

$RACK_ENV=production bundle exec puma -p 3000

而且,现在输出在下面,并且外部IP上的nginx响应保持不变.

And, now the output is below and the nginx response at the external IP remains the same.

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创建的puma进程似乎不与nginx通信,但不返回任何错误.

Now, both methods: RACK_ENV=production bundle exec puma -p 3000 and puma -e production -d -b unix:///tmp/web-app.sock --pidfile /tmp/puma.pid create puma processes that don't seem to communicate with nginx but do not return any errors.

编辑2 检查日志

我跑了

cat log/production.log

它返回:

I, [2016-02-02T##:##:##.###### #28802] INFO -- : ** [Bugsnag] Bugsnag exception handler 3.0.0 ready, api_key=####################

编辑2.5 检查更多日志我跑了:

EDIT 2.5 Checking More LogsI ran:

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:12016/02/02 11:10:26 [emerg] 28273#0: unknown directive "tream" in /etc/nginx/sites-enabled/web-appname.com:1

2016/02/02 11:09:52 [emerg] 28220#0: unknown directive "tream" in /etc/nginx/sites-enabled/web-appname.com:12016/02/02 11:10:26 [emerg] 28273#0: unknown directive "tream" in /etc/nginx/sites-enabled/web-appname.com:1

这些错误是由于我的文件缺少前3个字符引起的,此错误已得到修复.结论:我上面列出的日志中似乎没有任何提示.

Those errors were caused a bit ago from my file missing the first 3 characters, that error has since been fixed. In conclusion: there seem to be no errors in the logs that I have listed above that give me any hints.

编辑3

我目前的猜测是我错误地设置了/etc/nginx/sites-available/myapp.com文件.这是我使用的所有命名.

My guess currently is that I set up my /etc/nginx/sites-available/myapp.com file incorrectly. Here is all the naming that I have used.

当前名称为: web-app.com ,该URL只是IP地址,可以说 https://104.199.155.166/ .我的应用程序位于名为 web-app

Currently it is named: web-app.com, the url is just the ip address, lets say https://104.199.155.166/. My application is in a folder called 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

我对上述配置文件进行了许多更改,但我所做的任何更改都没有.我目前认为它是正确的配置.我很茫然,不胜感激任何建议.

I have made many changes to the above config file, and nothing that I do changes anything. I currently have it at what I believe to be the correct configuration. I am at a loss and would appreciate any suggestions.

小问题:如果同一VM上还有其他用户,并且他们可能安装了nginx并以不同的方式配置,是否可能导致问题?

Small question: if there are other users on the same VM and they may have nginx installed and configure differently, could that be causing the issues?

推荐答案

StackOverflow太讨厌代码标识不正确",所以我决定将所有答案都当作代码.

StackOverflow was being too annoying about "code not properly idented", so I decided to put all the answer as code.

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

这篇关于在puma,rails,nginx上设置Rails应用程序一切都在运行,但是nginx发送错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 16:42