1、安裝各種依賴的gem
? ??yum install make gcc openssl-devel zlib-devel gcc gcc-c++make autoconf readline-devel curl-devel expat-devel gettext-devel ncurese-develmysql-develhttpd-devel wget which
2、curl -O -Lhttps://cache.ruby-lang.org/pub/ruby/ruby-2.3.3.tar.gz? 下載
3格嘁、tar xf ruby-2.3.3.tar.gz? 解壓
4馍悟、cd ruby-2.3.3/
5识椰、./configure --prefix=/usr/local/ruby
6猴抹、make
7整陌、make install
8划纽、ruby -v
9脆侮、gem install rails-v = 5.1.6
10、rake secret RAILS_ENV=production? ? //生成production密碼
11勇劣、將上面生成的密碼放進(jìn)/etc/profile.d/st_rails_secret_key_env.sh中靖避,內(nèi)容如下
export SECRET_KEY_BASE='密碼'
12、puma.rb的設(shè)置:
# Puma can serve each request in a thread from an internal thread pool.
# The `threads` method setting takes two numbers: a minimum and maximum.
# Any libraries that use thread pools should be configured to match
# the maximum value specified for Puma. Default is set to 5 threads for minimum
# and maximum; this matches the default thread size of Active Record.
#
threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
threads threads_count, threads_count
# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
#
port? ? ? ? ENV.fetch("PORT") { 3001 }
# Specifies the `environment` that Puma will run in.
#
environment ENV.fetch("RAILS_ENV") { "development" }
# Specifies the number of `workers` to boot in clustered mode.
# Workers are forked webserver processes. If using threads and workers together
# the concurrency of the application would be max `threads` * `workers`.
# Workers do not work on JRuby or Windows (both of which do not support
# processes).
#
# workers ENV.fetch("WEB_CONCURRENCY") { 2 }
# Use the `preload_app!` method when specifying a `workers` number.
# This directive tells Puma to first boot the application and load code
# before forking the application. This takes advantage of Copy On Write
# process behavior so workers use less memory. If you use this option
# you need to make sure to reconnect any threads in the `on_worker_boot`
# block.
#
# preload_app!
# If you are preloading your application and using Active Record, it's
# recommended that you close any connections to the database before workers
# are forked to prevent connection leakage.
#
# before_fork do
#? ActiveRecord::Base.connection_pool.disconnect! if defined?(ActiveRecord)
# end
# The code in the `on_worker_boot` will be called if you are using
# clustered mode by specifying a number of `workers`. After each worker
# process is booted, this block will be run. If you are using the `preload_app!`
# option, you will want to use this block to reconnect to any threads
# or connections that may have been created at application boot, as Ruby
# cannot share connections between processes.
#
# on_worker_boot do
#? ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
# end
#
# Allow puma to be restarted by `rails restart` command.
plugin :tmp_restart
13比默、 nginx安裝
yum install nginx
配置文件在/etc/nginx/conf.d/
配置內(nèi)容如下:
upstream orange{
???????#server 127.0.0.1:3000;//development用筋蓖,就是測(cè)試用的
???????#keepalive 64;//development用,就是測(cè)試用的
???????server unix:/home/www/orange/tmp/sockets/puma.sock fail_timeout=0;//production用
}
server {
???????listen 8001;
???????server_name 網(wǎng)址退敦,不要http:https:;
???????location / {
??????????????? proxy_set_header Host$http_host;
??????????????? proxy_set_headerX-Forwarded_For $proxy_add_x_forwarded_for;
??????????????? proxy_redirect off;
??????????????? proxy_pass http://項(xiàng)目名;
??????????????? proxy_set_header Connection '';
?? ?????????????proxy_http_version 1.1;
??????????????? chunked_transfer_encoding off;
??????????????? proxy_buffering off;
??????????????? proxy_cache off;
???????}
???????location ~ \.(htm|html|shtml|gif|jpg|jpeg|png|ico|css|js|f|v|swf)$ {
?????????????? ?root 項(xiàng)目全路徑/public;
??????????????? access_log off;
??????????????? expires max;
???????}
???????location ~ ^/(frame/) {
??????????????? root 項(xiàng)目全路徑/public;
??????????????? access_log off;
??????????????? expires max;
???????}
???? ???error_page 500 502 503 504 /500.html;
???????client_max_body_size 4G;
???????keepalive_timeout 10;
}
nginx啟動(dòng):systemctl start nginx.service
nginx重啟:systemctl restart nginx.service
nginx狀態(tài):systemctl status nginx.service
如果一切進(jìn)展順利的話粘咖,現(xiàn)在你可以通過(guò)你的域名或IP來(lái)訪問(wèn)你的Web頁(yè)面來(lái)預(yù)覽一下Nginx的默認(rèn)頁(yè)面;
如果看到這個(gè)頁(yè)面,那么說(shuō)明你的CentOS 7 中 web服務(wù)器已經(jīng)正確安裝侈百。
開(kāi)機(jī)啟動(dòng)nginx: sudo systemctl enable nginx.service
網(wǎng)站文件存放默認(rèn)目錄
/usr/share/nginx/html
網(wǎng)站默認(rèn)站點(diǎn)配置
/etc/nginx/conf.d/default.conf
自定義Nginx站點(diǎn)配置文件存放目錄
/etc/nginx/conf.d/
Nginx全局配置
/etc/nginx/nginx.conf
Nginx啟動(dòng)
nginx -c nginx.conf
在這里你可以改變?cè)O(shè)置用戶運(yùn)行Nginx守護(hù)程序進(jìn)程一樣,和工作進(jìn)程的數(shù)量得到了Nginx正在運(yùn)行,等等瓮下。
14、 配置開(kāi)機(jī)啟動(dòng)puma:?
?路徑:/usr/lib/systemd/system/ 建立文件 ****.service 內(nèi)容如下:
? ? ? ? ? [Unit]
?Descriptionb = Puma HTTP Server
?After=network.target?
?? [Service]
?Type=simple?
?$Type=forking
?? User=root?
?? WorkingDirectory=項(xiàng)目路徑??
?? ExecStart=/bin/bash -lc 'bundle exec puma -e production -C 項(xiàng)目路徑/config/puma.rb' ?
?Restart=always
?RestartSec=30
?? [Install]
?WantedBy=multi-user.target?
? ? ? ?保存后:systemctl enable orange.service開(kāi)啟服務(wù)
?? ? ? 確保mariadb(數(shù)據(jù)庫(kù)),nginx,自定義腳本(puma)可以開(kāi)機(jī)啟動(dòng)钝域,即可讽坏! 查看開(kāi)機(jī)啟動(dòng)項(xiàng):systemctl list-unit-files ? ?