问题
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.
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...
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.
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
But the external web page returned the same nginx error.
How should I proceed? It seems that things are running but puma and nginx just are not talking?
EDIT 1
I did: `sudo chmod -R 0777 /home/myunsername/appname/log/`
Then:
$RACK_ENV=production bundle exec puma -p 3000
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
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.
EDIT 2 Checking Logs
I ran:
cat log/production.log
and it returned:
I, [2016-02-02T##:##:##.###### #28802] INFO -- : ** [Bugsnag] Bugsnag exception handler 3.0.0 ready, api_key=####################
EDIT 2.5 Checking More Logs I ran:
tail -f /var/log/nginx/error.log
and it returned:
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
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.
EDIT 3
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.
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;
}
}
EDIT 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.
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?
回答1:
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
来源:https://stackoverflow.com/questions/35152369/setting-up-a-rails-app-on-puma-rails-nginx-everything-is-running-but-nginx-se