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、将上面生成的密码放进/etc/profile.d/st_rails_secret_key_env.sh中,内容如下
export SECRET_KEY_BASE='密码'
12、puma.rb的设置:
# 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/
配置内容如下:
upstream orange{
#server 127.0.0.1:3000;//development用,就是测试用的
#keepalive 64;//development用,就是测试用的
server unix:/home/www/orange/tmp/sockets/puma.sock fail_timeout=0;//production用
}
server {
listen 8001;
server_name 网址,不要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://项目名;
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 项目全路径/public;
access_log off;
expires max;
}
location ~ ^/(frame/) {
root 项目全路径/public;
access_log off;
expires max;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
nginx启动:systemctl start nginx.service
nginx重启:systemctl restart nginx.service
nginx状态:systemctl status nginx.service
如果一切进展顺利的话,现在你可以通过你的域名或IP来访问你的Web页面来预览一下Nginx的默认页面;
如果看到这个页面,那么说明你的CentOS 7 中 web服务器已经正确安装。
开机启动nginx: sudo systemctl enable nginx.service
网站文件存放默认目录
/usr/share/nginx/html
网站默认站点配置
/etc/nginx/conf.d/default.conf
自定义Nginx站点配置文件存放目录
/etc/nginx/conf.d/
Nginx全局配置
/etc/nginx/nginx.conf
Nginx启动
nginx -c nginx.conf
在这里你可以改变设置用户运行Nginx守护程序进程一样,和工作进程的数量得到了Nginx正在运行,等等。
14、 配置开机启动puma:
路径:/usr/lib/systemd/system/ 建立文件 ****.service 内容如下:
[Unit]
Descriptionb = Puma HTTP Server
After=network.target
[Service]
Type=simple
$Type=forking
User=root
WorkingDirectory=项目路径
ExecStart=/bin/bash -lc 'bundle exec puma -e production -C 项目路径/config/puma.rb'
Restart=always
RestartSec=30
[Install]
WantedBy=multi-user.target
保存后:systemctl enable orange.service开启服务
确保mariadb(数据库),nginx,自定义脚本(puma)可以开机启动,即可! 查看开机启动项:systemctl list-unit-files
网友评论