[英]Centos 7x64 - Deploy Rails using Nginx and Unicorn
I've followed this tutorial How to deploy rails apps using unicorn and nginx on CentOS 6.5 to deploy in Centos 7x64.我已经按照本教程如何在 CentOS 6.5 上使用 unicorn 和 nginx 部署 rails 应用程序以在 Centos 7x64 中部署。
The first time I made it work accessing to http://[my-ip]:8080/tasks
, but now after repeating the exercise many times I only see a 'can not access' in the browser.我第一次成功访问
http://[my-ip]:8080/tasks
,但现在在多次重复练习后,我只在浏览器中看到“无法访问”。 But I can see Nginx start page in http://[my-ip]
.但是我可以在
http://[my-ip]
看到 Nginx 起始页。
Questions:问题:
General settings
通用设置
echo "export LC_ALL=en_US.UTF-8" >> /etc/profile
export LC_ALL=en_US.UTF-8
yum -y update
yum groupinstall -y 'development tools'
rpm -Uvh https://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
yum repolist
yum --disablerepo="*" --enablerepo="epel" list available
yum --enablerepo=epel info htop
yum --enablerepo=epel install -y htop
yum install -y curl-devel nano sqlite-devel libyaml-devel
Install Ruby and RoR
安装 Ruby 和 RoR
sudo yum install -y ruby
sudo yum install -y gcc g++ make automake autoconf curl-devel openssl-devel zlib-devel httpd-devel apr-devel apr-util-devel sqlite-devel
sudo yum install -y ruby-rdoc ruby-devel
sudo yum install -y rubygems
sudo gem update
sudo gem update --system
sudo gem install rails --no-rdoc --no-ri
Install Unicorn
安装独角兽
gem install unicorn
Install Nginx
安装 Nginx
sudo yum install -y nginx
ifconfig eth0 | grep inet | awk '{ print $2 }'
Install NodeJS
安装 Node.js
sudo yum install -y gcc gcc-c++
wget http://nodejs.org/dist/v0.10.36/node-v0.10.36.tar.gz
tar xzvf node-v* && cd node-v*
./configure
make
sudo make install
node --version
# Create a sample Rails application
cd /var
mkdir www
cd www
rails new my_app
# Enter the application directory
cd my_app
# Create a sample resource
rails generate scaffold Task title:string note:text
# Create a sample database
RAILS_ENV=development rake db:migrate
RAILS_ENV=production rake db:migrate
# Create a directory to hold the PID files
mkdir pids
my_app/config/unicorn.rb
my_app/config/unicorn.rb
# Set the working application directory
# working_directory "/path/to/your/app"
working_directory "/var/www/my_app"
# Unicorn PID file location
# pid "/path/to/pids/unicorn.pid"
pid "/var/www/my_app/pids/unicorn.pid"
# Path to logs
# stderr_path "/path/to/log/unicorn.log"
# stdout_path "/path/to/log/unicorn.log"
stderr_path "/var/www/my_app/log/unicorn.log"
stdout_path "/var/www/my_app/log/unicorn.log"
# Unicorn socket
listen "/tmp/unicorn.[app name].sock"
listen "/tmp/unicorn.myapp.sock"
# Number of processes
# worker_processes 4
worker_processes 2
# Time-out
timeout 30
/etc/nginx/conf.d/default.conf
/etc/nginx/conf.d/default.conf
upstream app {
# Path to Unicorn SOCK file, as defined previously
server unix:/tmp/unicorn.myapp.sock fail_timeout=0;
}
server {
listen 80;
server_name localhost;
# Application root, as defined previously
root /root/my_app/public;
try_files $uri/index.html $uri @app;
location @app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
unicorn_rails -c config/unicorn.rb -D
systemctl start nginx.service
systemctl status nginx.service
nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled)
Active: active (running) since Thu 2015-01-29 13:37:08 EST; 1min 57s ago
Process: 642 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
Process: 604 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
Main PID: 650 (nginx)
CGroup: /system.slice/nginx.service
├─650 nginx: master process /usr/sbin/nginx
└─654 nginx: worker process
demo nginx[604]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
demo nginx[604]: nginx: configuration file /etc/nginx/nginx.conf test is successful
demo systemd[1]: Failed to read PID from file /run/nginx.pid: Invalid argument
demo systemd[1]: Started The nginx HTTP and reverse proxy server.
demo systemd[1]: Started The nginx HTTP and reverse proxy server.
log/unicorn.log
日志/独角兽.log
I, [2015-01-29T14:45:58.886225 #11502] INFO -- : listening on addr=/tmp/unicorn.[app name].sock fd=10
I, [2015-01-29T14:45:58.886616 #11502] INFO -- : listening on addr=/tmp/unicorn.myapp.sock fd=11
I, [2015-01-29T14:45:58.886891 #11502] INFO -- : worker=0 spawning...
I, [2015-01-29T14:45:58.887657 #11502] INFO -- : worker=1 spawning...
I, [2015-01-29T14:45:58.888673 #11505] INFO -- : worker=0 spawned pid=11505
I, [2015-01-29T14:45:58.889029 #11505] INFO -- : Refreshing Gem list
I, [2015-01-29T14:45:58.891061 #11502] INFO -- : master process ready
I, [2015-01-29T14:45:58.918331 #11508] INFO -- : worker=1 spawned pid=11508
I, [2015-01-29T14:45:58.918732 #11508] INFO -- : Refreshing Gem list
I, [2015-01-29T14:46:03.608903 #11508] INFO -- : worker=1 ready
I, [2015-01-29T14:46:03.609694 #11505] INFO -- : worker=0 ready
config/production.log
配置/生产.log
D, [2015-01-28T22:22:34.225698 #1864] DEBUG -- : (3.6ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL)
D, [2015-01-28T22:22:34.226055 #1864] DEBUG -- : (0.1ms) select sqlite_version(*)
D, [2015-01-28T22:22:34.229402 #1864] DEBUG -- : (2.8ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
D, [2015-01-28T22:22:34.230780 #1864] DEBUG -- : ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
I, [2015-01-28T22:22:34.234599 #1864] INFO -- : Migrating to CreateTasks (20150129032219)
D, [2015-01-28T22:22:34.235363 #1864] DEBUG -- : (0.1ms) begin transaction
D, [2015-01-28T22:22:34.237769 #1864] DEBUG -- : (0.5ms) CREATE TABLE "tasks" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar, "note" text, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL)
D, [2015-01-28T22:22:34.245241 #1864] DEBUG -- : SQL (0.2ms) INSERT INTO "schema_migrations" ("version") VALUES (?) [["version", "20150129032219"]]
D, [2015-01-28T22:22:34.248567 #1864] DEBUG -- : (3.0ms) commit transaction
/var/log/nginx/error.log
/var/log/nginx/error.log
Empty
[root@demo my_app]# rails s
Warning: Running `gem pristine --all` to regenerate your installed gemspecs (and deleting then reinstalling your bundle if you use bundle --path) will improve the startup performance of Spring.
=> Booting WEBrick
=> Rails 4.2.0 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2015-01-29 14:59:12] INFO WEBrick 1.3.1
[2015-01-29 14:59:12] INFO ruby 2.0.0 (2013-11-22) [x86_64-linux]
[2015-01-29 14:59:12] INFO WEBrick::HTTPServer#start: pid=11560 port=3000
Failed to read PID from file /run/nginx.pid: Invalid argument
.Failed to read PID from file /run/nginx.pid: Invalid argument
。 Maybe your config doesn't gets loaded?"/var/www/my_app/log/unicorn.log"
regarding to your config and the Rails log file is "/var/www/my_app/log/production.log"
."/var/www/my_app/log/unicorn.log"
关于你的配置,Rails 日志文件是"/var/www/my_app/log/production.log"
。 The log file of nginx is somewhere under "/var/log/nginx/"
, but I am not sure about that. "/var/log/nginx/"
下的某个地方,但我不确定。 Please share your log files with us when you haven't find the problem then.当您还没有发现问题时,请与我们分享您的日志文件。
Regarding to your questions:关于你的问题:
default.conf
file.default.conf
文件中。In dir rails:在目录导轨中:
rm -rf public/assets
rake assets:clean RAILS_ENV=development
At the end, please apply the below permissions最后,请应用以下权限
chown -R nginx:nginx /www/[APLICACCION]/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.