如何在 Ubuntu 14.03 Server 上安装 mina 的一键部署环境

Rails
2016-02-11 23:50

目录

假期里把 AWS EC2 上的两台 Ubuntu 实例重新部署了一下,遇到不少坑,也从社区里面得到了不少帮助。

整理成文,希望能帮到Ruby China 社区里的其他小伙伴。1

转帖的时候请注明原文地址2,谢谢。

1. 将自己的Key传到服务器上

ssh-agent bash
ssh-add ~/.ssh/ec2-instance-key.pem
ssh-copy-id -i ~/.ssh/id_rsa.pub <user_name>@<server_domain>

测试

ssh <user_name>@<server_domain>

2. 配置 Ubuntu 系统

sudo wget -O- https://www.zhengweiyu.com/installer/init-ubuntu.sh | sh

3. 安装 rvm

sudo wget -O- https://www.zhengweiyu.com/installer/rvm.sh | sh

4. 安装 Web 服务

4.1 Nginx + Passanger

sudo wget -O- https://www.zhengweiyu.com/installer/nginx-passanger.sh | sh

现在修改 nginx 配置,编辑 /etc/nginx/nginx.conf,找到这两行注释:

# passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
# passenger_ruby /usr/bin/ruby;

去除 ‘#’ 即在 nginx 中启用了 passanger

4.2 Nginx + PHP5 + PHP5-FPM

sudo wget -O- https://www.zhengweiyu.com/installer/nginx-php5-php5fpm.sh | sh

5. 安装数据库

5.1 PostgreSQL

sudo wget -O- https://www.zhengweiyu.com/installer/postgresql.sh | sh

登录数据库

sql sudo -u postgres psql postgres 

创建数据库和用户

sudo -u postgres psql postgres
create user "<user name>" with password '<password>';
/* 建议 <user name> 和 <database name> 相同 */
create database "<database name>" owner "<user name>"; 
grant all privileges on database <database name> to <user name>; 

5.2 MySQL

sudo wget -O- https://www.zhengweiyu.com/installer/mysql.sh | sh

登录数据库

mysql -u root -p

创建数据库和用户

create database <database_name>;
create user <user_name>@localhost identified by '<password>';
/* 建议 <user name> 和 <database name> 相同 */
grant all privileges on <user_name>.* to <database_name>@localhost;
flush privileges;

6. 配置 mina 环境

gem install mina

在项目根目录下,执行

mina init

编辑 config/deploy.rb

6.1 Passanger 环境

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
	require 'mina/bundler'
	require 'mina/rails'
	require 'mina/git'
	# require 'mina/rbenv'  # for rbenv support. (http://rbenv.org)
	require 'mina/rvm'    # for rvm support. (http://rvm.io)
	require 'mina_sidekiq/tasks'
	require 'mina/foreman'

	# Basic settings:
	#   domain       - The hostname to SSH to.
	#   deploy_to    - Path to deploy into.
	#   repository   - Git repo to clone from. (needed by mina/git)
	#   branch       - Branch name to deploy. (needed by mina/git)
	set :rails_env, 'production'

	set :domain, 'Server domian'
	set :unit_name, 'Git unit name'
	set :app_name, 'Git app name'

	# Optional settings:
	set :user, 'Your username'    # Username in the server to SSH to.
	set :port, '22'     # SSH port number.
	#   set :forward_agent, true     # SSH forward_agent.

	set :deploy_to, "/home/#{user}/webapps/#{rails_env}/#{app_name}"

	set :app_path,   "#{deploy_to}/#{current_path}"
	set :repository, "[email protected]:#{unit_name}/#{app_name}.git"
	set :branch, 'master'

	# For system-wide RVM install.
	set :rvm_path, '/usr/local/rvm/bin/rvm'

	# Manually create these paths in shared/ (eg: shared/config/database.yml) in your server.
	# They will be linked in the 'deploy:link_shared_paths' step.
	set :shared_paths, ['config/application.yml', 'config/database.yml','log', 'tmp']

	# Keep the recent 3 release
	set :keep_releases, '3'

	# Foreman
	set :foreman_sudo, true
	set :foreman_app, "#{app_name}"
	set :foreman_user, "#{user}"
	set :foreman_log, "#{deploy_to}/shared/log"

	# This task is the environment that is loaded for most commands, such as
	# `mina deploy` or `mina rake`.
	task :environment do
	  # If you're using rbenv, use this to load the rbenv environment.
	  # Be sure to commit your .ruby-version or .rbenv-version to your repository.
	  # invoke :'rbenv:load'

	  # For those using RVM, use this to load an RVM [email protected]
	  invoke :'rvm:use[[email protected]]'
	end

	# Put any custom mkdir's in here for when `mina setup` is ran.
	# For Rails apps, we'll make some of the shared paths that are shared between
	# all releases.
	task :setup => :environment do  
	  queue! %[mkdir -p "#{deploy_to}/shared/log"]
	  queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/log"]
	  
	  queue! %[mkdir -p "#{deploy_to}/shared/tmp"]
	  queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/tmp"]

	  queue! %[mkdir -p "#{deploy_to}/shared/config"]
	  queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/config"]

	  queue! %[touch "#{deploy_to}/shared/config/database.yml"]
	  queue %[echo "-----> Be sure to edit 'shared/config/database.yml'."]

	  queue! %[touch "#{deploy_to}/shared/config/secrets.yml"]
	  queue %[echo "-----> Be sure to edit 'shared/config/secrets.yml'."]
	  
	  # sidekiq needs a place to store its pid file and log file
	  queue! %[mkdir -p "#{deploy_to}/shared/pids/"]
	  queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/pids/"]
	end

	task :log do
	  queue 'echo "Contents of the log file are as follows:"'
	  queue "tail -f -n 100 /var/www/#{app_name}/log/error.log"
	end

	desc "Deploys the current version to the server."  
	task :deploy => :environment do  
	  deploy do
	    invoke :'sidekiq:quiet'
	    invoke :'git:clone'
	    invoke :'deploy:link_shared_paths'
	    invoke :'bundle:install'
	    invoke :'rails:db_migrate'
	    invoke :'rails:assets_precompile'
	    invoke :'deploy:cleanup'

	    to :launch do
	      invoke :'passenger:restart'
	      invoke :'sidekiq:restart'
	    end
	  end
	end

	desc "Restarts the nginx server."  
	task :restart do  
	  invoke :'passenger:restart'
	end

	namespace :passenger do  
	  task :restart do
	    queue "touch #{deploy_to}/shared/tmp/restart.txt"
	  end
	end  

6.2 Jekyll 环境

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
	require 'mina/bundler'
	require 'mina/rails'
	require 'mina/git'
	# require 'mina/rbenv'  # for rbenv support. (http://rbenv.org)
	require 'mina/rvm'    # for rvm support. (http://rvm.io)

	# Basic settings:
	#   domain       - The hostname to SSH to.
	#   deploy_to    - Path to deploy into.
	#   repository   - Git repo to clone from. (needed by mina/git)
	#   branch       - Branch name to deploy. (needed by mina/git)
	set :rails_env, 'production'

	set :domain, 'Server domian'
	set :unit_name, 'Git unit name'
	set :app_name, 'Git app name'

	# Optional settings:
	set :user, 'Your username'    # Username in the server to SSH to.
	set :port, '22'     # SSH port number.
	#   set :forward_agent, true     # SSH forward_agent.

	set :deploy_to, "/home/#{user}/webapps/#{rails_env}/#{app_name}"

	set :app_path,   "#{deploy_to}/#{current_path}"
	set :repository, "[email protected]:#{unit_name}/#{app_name}.git"
	set :branch, 'master'

	# For system-wide RVM install.
	set :rvm_path, '/usr/local/rvm/bin/rvm'

	# Manually create these paths in shared/ (eg: shared/config/database.yml) in your server.
	# They will be linked in the 'deploy:link_shared_paths' step.
	set :shared_paths, ['log']

	# Keep the recent 3 release
	set :keep_releases, '3'

	# This task is the environment that is loaded for most commands, such as
	# `mina deploy` or `mina rake`.
	task :environment do
	  # If you're using rbenv, use this to load the rbenv environment.
	  # Be sure to commit your .ruby-version or .rbenv-version to your repository.
	  # invoke :'rbenv:load'

	  # For those using RVM, use this to load an RVM [email protected]
	  invoke :'rvm:use[[email protected]]'
	end

	# Put any custom mkdir's in here for when `mina setup` is ran.
	# For Rails apps, we'll make some of the shared paths that are shared between
	# all releases.
	task :setup => :environment do  
	  queue! %[mkdir -p "#{deploy_to}/shared/log"]
	  queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/log"]
	end

	task :log do
	  queue 'echo "Contents of the log file are as follows:"'
	  queue "tail -f -n 100 /var/www/#{app_name}/log/error.log"
	end

	desc "Deploys the current version to the server."  
	task :deploy => :environment do  
	  deploy do
	    # invoke :'sidekiq:quiet'
	    invoke :'git:clone'
	    invoke :'deploy:link_shared_paths'
	    invoke :'deploy:cleanup'

	    to :launch do
	      invoke :'nginx:restart'
	    end
	  end
	end

	desc "Restarts the nginx server."  
	task :restart do  
	  invoke :'nginx:restart'
	end

6.3 PHP 环境

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
	require 'mina/bundler'
	require 'mina/rails'
	require 'mina/git'
	# require 'mina/rbenv'  # for rbenv support. (http://rbenv.org)
	require 'mina/rvm'    # for rvm support. (http://rvm.io)
	require 'mina_sidekiq/tasks'
	require 'mina/foreman'

	# Basic settings:
	#   domain       - The hostname to SSH to.
	#   deploy_to    - Path to deploy into.
	#   repository   - Git repo to clone from. (needed by mina/git)
	#   branch       - Branch name to deploy. (needed by mina/git)
	set :rails_env, 'production'

	set :domain, 'Server domian'
	set :unit_name, 'Git unit name'
	set :app_name, 'Git app name'

	# Optional settings:
	set :user, 'Your username'    # Username in the server to SSH to.
	set :port, '22'     # SSH port number.
	#   set :forward_agent, true     # SSH forward_agent.

	set :deploy_to, "/home/#{user}/webapps/#{rails_env}/#{app_name}"

	set :app_path,   "#{deploy_to}/#{current_path}"
	set :repository, "[email protected]:#{unit_name}/#{app_name}.git"
	set :branch, 'master'

	# For system-wide RVM install.
	set :rvm_path, '/usr/local/rvm/bin/rvm'

	# Manually create these paths in shared/ (eg: shared/config/database.yml) in your server.
	# They will be linked in the 'deploy:link_shared_paths' step.
	set :shared_paths, ['wp-content/cache','wp-content/uploads', 'log', 'tmp']

	# Keep the recent 3 release
	set :keep_releases, '3'

	# This task is the environment that is loaded for most commands, such as
	# `mina deploy` or `mina rake`.
	task :environment do
	  # If you're using rbenv, use this to load the rbenv environment.
	  # Be sure to commit your .ruby-version or .rbenv-version to your repository.
	  # invoke :'rbenv:load'

	  # For those using RVM, use this to load an RVM [email protected]
	  invoke :'rvm:use[[email protected]]'
	end

	# Put any custom mkdir's in here for when `mina setup` is ran.
	# For Rails apps, we'll make some of the shared paths that are shared between
	# all releases.
	task :setup => :environment do  
	  queue! %[mkdir -p "#{deploy_to}/shared/log"]
	  queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/log"]
	  
	  queue! %[mkdir -p "#{deploy_to}/shared/tmp"]
	  queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/tmp"]

	  queue! %[mkdir -p "#{deploy_to}/shared/wp-content/uploads"]
	  queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/wp-content/uploads"]

	  queue! %[mkdir -p "#{deploy_to}/shared/wp-content/cache"]
	  queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/wp-content/cache"]
	end

	task :log do
	  queue 'echo "Contents of the log file are as follows:"'
	  queue "tail -f -n 100 /var/www/#{app_name}/log/error.log"
	end

	desc "Deploys the current version to the server."  
	task :deploy => :environment do  
	  deploy do
	    # invoke :'sidekiq:quiet'
	    invoke :'git:clone'
	    invoke :'deploy:link_shared_paths'
	    invoke :'deploy:cleanup'

	    to :launch do
	      invoke :'nginx:restart'
	    end
	  end
	end

	desc "Restarts the nginx server."  
	task :restart do  
	  invoke :'nginx:restart'
	end

Mina 部署项目

mina setup
mina deploy

7. 建立 Nginx 配置文件

sudo mkdir -p /var/www
cd /var/www
sudo ln -s /home/<user_name>/webapps/production/<project-dir>/current <project-dir>

建立 nginx 的配置文件

cd /etc/nginx/sites-available   sudo nano <your domain>

7.1 Passanger 的 nginx 文件

1
2
3
4
5
6
7
8
9
10
11
12
13
	server {
	    listen 80;
	    server_name <your domian>;
	    passenger_enabled on;
	    root /var/www/<project-dir>/public;

	    access_log off;
	    error_log /var/www/<project-dir>/log/error.log;

	    error_page 500 502 503 504 /500.html;
	    client_max_body_size 4G;
	    keepalive_timeout 10;
	}

7.2 Jekyll 的 nginx 文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
	server {
		listen 80;
		# listen [::]:80 ipv6only=on;

		root /var/www/<project-dir>/_site;
		index index.html;

		server_name <your domian>;
	        
		access_log off;
		error_log /var/www/<project-dir>/log/error.log;	 
		

		error_page 404 /404.html;

		error_page 500 502 503 504 /50x.html;
		location = /50x.html {
			root /usr/share/nginx/html;
		}
	}

7.3 PHP 的 nginx 文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
	server {
		listen 80;
		# listen [::]:80 ipv6only=on;

		root /var/www/<project-dir>;
		index index.php index.html index.htm;

		server_name <your domian>;
	        
		location / {
			# try_files $uri $uri/ =404;
			try_files $uri $uri/ /index.php?q=$uri&$args;
		}
	        
		access_log off;
		error_log /var/www/<project-dir>/log/error.log;	 
		

		error_page 404 /404.html;

		error_page 500 502 503 504 /50x.html;
		location = /50x.html {
			root /usr/share/nginx/html;
		}

		location ~ \.php$ {
			try_files $uri =404;
			fastcgi_split_path_info ^(.+\.php)(/.+)$;
			fastcgi_pass unix:/var/run/php5-fpm.sock;
			fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
			fastcgi_index index.php;
			include fastcgi_params;
		}
	}

8. 链接目录并重启 Nginx

链接目录

cd /etc/nginx//sites-enabled/
sudo ln -s ../sites-available/<your domian> <your domian>

重启 nginx 服务

sudo service nginx restart

如果看到

  • Restarting nginx nginx [ OK ]

说明配置成功。

9. 一键部署脚本

sudo wget -O- https://www.zhengweiyu.com/installer/deploy.sh | sh
  1. 相关 *.sh 均可以下载,根据自己的需要编辑使用。 

  2. http://www.zhengweiyu.com/2016/02/11/how-to-install-mina-env.html 

加载 Disqus 评论

© 版权所有 悟理 2013-2019
Powered By Jekyll & Semantic UI

如何在 Ubuntu 14.03 Server 上安装 mina 的一键部署环境

Rails
2016-02-11 23:50

目录

假期里把 AWS EC2 上的两台 Ubuntu 实例重新部署了一下,遇到不少坑,也从社区里面得到了不少帮助。

整理成文,希望能帮到Ruby China 社区里的其他小伙伴。1

转帖的时候请注明原文地址2,谢谢。

1. 将自己的Key传到服务器上

ssh-agent bash
ssh-add ~/.ssh/ec2-instance-key.pem
ssh-copy-id -i ~/.ssh/id_rsa.pub <user_name>@<server_domain>

测试

ssh <user_name>@<server_domain>

2. 配置 Ubuntu 系统

sudo wget -O- https://www.zhengweiyu.com/installer/init-ubuntu.sh | sh

3. 安装 rvm

sudo wget -O- https://www.zhengweiyu.com/installer/rvm.sh | sh

4. 安装 Web 服务

4.1 Nginx + Passanger

sudo wget -O- https://www.zhengweiyu.com/installer/nginx-passanger.sh | sh

现在修改 nginx 配置,编辑 /etc/nginx/nginx.conf,找到这两行注释:

# passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
# passenger_ruby /usr/bin/ruby;

去除 ‘#’ 即在 nginx 中启用了 passanger

4.2 Nginx + PHP5 + PHP5-FPM

sudo wget -O- https://www.zhengweiyu.com/installer/nginx-php5-php5fpm.sh | sh

5. 安装数据库

5.1 PostgreSQL

sudo wget -O- https://www.zhengweiyu.com/installer/postgresql.sh | sh

登录数据库

sql sudo -u postgres psql postgres 

创建数据库和用户

sudo -u postgres psql postgres
create user "<user name>" with password '<password>';
/* 建议 <user name> 和 <database name> 相同 */
create database "<database name>" owner "<user name>"; 
grant all privileges on database <database name> to <user name>; 

5.2 MySQL

sudo wget -O- https://www.zhengweiyu.com/installer/mysql.sh | sh

登录数据库

mysql -u root -p

创建数据库和用户

create database <database_name>;
create user <user_name>@localhost identified by '<password>';
/* 建议 <user name> 和 <database name> 相同 */
grant all privileges on <user_name>.* to <database_name>@localhost;
flush privileges;

6. 配置 mina 环境

gem install mina

在项目根目录下,执行

mina init

编辑 config/deploy.rb

6.1 Passanger 环境

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
	require 'mina/bundler'
	require 'mina/rails'
	require 'mina/git'
	# require 'mina/rbenv'  # for rbenv support. (http://rbenv.org)
	require 'mina/rvm'    # for rvm support. (http://rvm.io)
	require 'mina_sidekiq/tasks'
	require 'mina/foreman'

	# Basic settings:
	#   domain       - The hostname to SSH to.
	#   deploy_to    - Path to deploy into.
	#   repository   - Git repo to clone from. (needed by mina/git)
	#   branch       - Branch name to deploy. (needed by mina/git)
	set :rails_env, 'production'

	set :domain, 'Server domian'
	set :unit_name, 'Git unit name'
	set :app_name, 'Git app name'

	# Optional settings:
	set :user, 'Your username'    # Username in the server to SSH to.
	set :port, '22'     # SSH port number.
	#   set :forward_agent, true     # SSH forward_agent.

	set :deploy_to, "/home/#{user}/webapps/#{rails_env}/#{app_name}"

	set :app_path,   "#{deploy_to}/#{current_path}"
	set :repository, "[email protected]:#{unit_name}/#{app_name}.git"
	set :branch, 'master'

	# For system-wide RVM install.
	set :rvm_path, '/usr/local/rvm/bin/rvm'

	# Manually create these paths in shared/ (eg: shared/config/database.yml) in your server.
	# They will be linked in the 'deploy:link_shared_paths' step.
	set :shared_paths, ['config/application.yml', 'config/database.yml','log', 'tmp']

	# Keep the recent 3 release
	set :keep_releases, '3'

	# Foreman
	set :foreman_sudo, true
	set :foreman_app, "#{app_name}"
	set :foreman_user, "#{user}"
	set :foreman_log, "#{deploy_to}/shared/log"

	# This task is the environment that is loaded for most commands, such as
	# `mina deploy` or `mina rake`.
	task :environment do
	  # If you're using rbenv, use this to load the rbenv environment.
	  # Be sure to commit your .ruby-version or .rbenv-version to your repository.
	  # invoke :'rbenv:load'

	  # For those using RVM, use this to load an RVM [email protected]
	  invoke :'rvm:use[[email protected]]'
	end

	# Put any custom mkdir's in here for when `mina setup` is ran.
	# For Rails apps, we'll make some of the shared paths that are shared between
	# all releases.
	task :setup => :environment do  
	  queue! %[mkdir -p "#{deploy_to}/shared/log"]
	  queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/log"]
	  
	  queue! %[mkdir -p "#{deploy_to}/shared/tmp"]
	  queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/tmp"]

	  queue! %[mkdir -p "#{deploy_to}/shared/config"]
	  queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/config"]

	  queue! %[touch "#{deploy_to}/shared/config/database.yml"]
	  queue %[echo "-----> Be sure to edit 'shared/config/database.yml'."]

	  queue! %[touch "#{deploy_to}/shared/config/secrets.yml"]
	  queue %[echo "-----> Be sure to edit 'shared/config/secrets.yml'."]
	  
	  # sidekiq needs a place to store its pid file and log file
	  queue! %[mkdir -p "#{deploy_to}/shared/pids/"]
	  queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/pids/"]
	end

	task :log do
	  queue 'echo "Contents of the log file are as follows:"'
	  queue "tail -f -n 100 /var/www/#{app_name}/log/error.log"
	end

	desc "Deploys the current version to the server."  
	task :deploy => :environment do  
	  deploy do
	    invoke :'sidekiq:quiet'
	    invoke :'git:clone'
	    invoke :'deploy:link_shared_paths'
	    invoke :'bundle:install'
	    invoke :'rails:db_migrate'
	    invoke :'rails:assets_precompile'
	    invoke :'deploy:cleanup'

	    to :launch do
	      invoke :'passenger:restart'
	      invoke :'sidekiq:restart'
	    end
	  end
	end

	desc "Restarts the nginx server."  
	task :restart do  
	  invoke :'passenger:restart'
	end

	namespace :passenger do  
	  task :restart do
	    queue "touch #{deploy_to}/shared/tmp/restart.txt"
	  end
	end  

6.2 Jekyll 环境

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
	require 'mina/bundler'
	require 'mina/rails'
	require 'mina/git'
	# require 'mina/rbenv'  # for rbenv support. (http://rbenv.org)
	require 'mina/rvm'    # for rvm support. (http://rvm.io)

	# Basic settings:
	#   domain       - The hostname to SSH to.
	#   deploy_to    - Path to deploy into.
	#   repository   - Git repo to clone from. (needed by mina/git)
	#   branch       - Branch name to deploy. (needed by mina/git)
	set :rails_env, 'production'

	set :domain, 'Server domian'
	set :unit_name, 'Git unit name'
	set :app_name, 'Git app name'

	# Optional settings:
	set :user, 'Your username'    # Username in the server to SSH to.
	set :port, '22'     # SSH port number.
	#   set :forward_agent, true     # SSH forward_agent.

	set :deploy_to, "/home/#{user}/webapps/#{rails_env}/#{app_name}"

	set :app_path,   "#{deploy_to}/#{current_path}"
	set :repository, "[email protected]:#{unit_name}/#{app_name}.git"
	set :branch, 'master'

	# For system-wide RVM install.
	set :rvm_path, '/usr/local/rvm/bin/rvm'

	# Manually create these paths in shared/ (eg: shared/config/database.yml) in your server.
	# They will be linked in the 'deploy:link_shared_paths' step.
	set :shared_paths, ['log']

	# Keep the recent 3 release
	set :keep_releases, '3'

	# This task is the environment that is loaded for most commands, such as
	# `mina deploy` or `mina rake`.
	task :environment do
	  # If you're using rbenv, use this to load the rbenv environment.
	  # Be sure to commit your .ruby-version or .rbenv-version to your repository.
	  # invoke :'rbenv:load'

	  # For those using RVM, use this to load an RVM [email protected]t.
	  invoke :'rvm:use[[email protected]]'
	end

	# Put any custom mkdir's in here for when `mina setup` is ran.
	# For Rails apps, we'll make some of the shared paths that are shared between
	# all releases.
	task :setup => :environment do  
	  queue! %[mkdir -p "#{deploy_to}/shared/log"]
	  queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/log"]
	end

	task :log do
	  queue 'echo "Contents of the log file are as follows:"'
	  queue "tail -f -n 100 /var/www/#{app_name}/log/error.log"
	end

	desc "Deploys the current version to the server."  
	task :deploy => :environment do  
	  deploy do
	    # invoke :'sidekiq:quiet'
	    invoke :'git:clone'
	    invoke :'deploy:link_shared_paths'
	    invoke :'deploy:cleanup'

	    to :launch do
	      invoke :'nginx:restart'
	    end
	  end
	end

	desc "Restarts the nginx server."  
	task :restart do  
	  invoke :'nginx:restart'
	end

6.3 PHP 环境

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
	require 'mina/bundler'
	require 'mina/rails'
	require 'mina/git'
	# require 'mina/rbenv'  # for rbenv support. (http://rbenv.org)
	require 'mina/rvm'    # for rvm support. (http://rvm.io)
	require 'mina_sidekiq/tasks'
	require 'mina/foreman'

	# Basic settings:
	#   domain       - The hostname to SSH to.
	#   deploy_to    - Path to deploy into.
	#   repository   - Git repo to clone from. (needed by mina/git)
	#   branch       - Branch name to deploy. (needed by mina/git)
	set :rails_env, 'production'

	set :domain, 'Server domian'
	set :unit_name, 'Git unit name'
	set :app_name, 'Git app name'

	# Optional settings:
	set :user, 'Your username'    # Username in the server to SSH to.
	set :port, '22'     # SSH port number.
	#   set :forward_agent, true     # SSH forward_agent.

	set :deploy_to, "/home/#{user}/webapps/#{rails_env}/#{app_name}"

	set :app_path,   "#{deploy_to}/#{current_path}"
	set :repository, "[email protected]:#{unit_name}/#{app_name}.git"
	set :branch, 'master'

	# For system-wide RVM install.
	set :rvm_path, '/usr/local/rvm/bin/rvm'

	# Manually create these paths in shared/ (eg: shared/config/database.yml) in your server.
	# They will be linked in the 'deploy:link_shared_paths' step.
	set :shared_paths, ['wp-content/cache','wp-content/uploads', 'log', 'tmp']

	# Keep the recent 3 release
	set :keep_releases, '3'

	# This task is the environment that is loaded for most commands, such as
	# `mina deploy` or `mina rake`.
	task :environment do
	  # If you're using rbenv, use this to load the rbenv environment.
	  # Be sure to commit your .ruby-version or .rbenv-version to your repository.
	  # invoke :'rbenv:load'

	  # For those using RVM, use this to load an RVM [email protected]
	  invoke :'rvm:use[[email protected]]'
	end

	# Put any custom mkdir's in here for when `mina setup` is ran.
	# For Rails apps, we'll make some of the shared paths that are shared between
	# all releases.
	task :setup => :environment do  
	  queue! %[mkdir -p "#{deploy_to}/shared/log"]
	  queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/log"]
	  
	  queue! %[mkdir -p "#{deploy_to}/shared/tmp"]
	  queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/tmp"]

	  queue! %[mkdir -p "#{deploy_to}/shared/wp-content/uploads"]
	  queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/wp-content/uploads"]

	  queue! %[mkdir -p "#{deploy_to}/shared/wp-content/cache"]
	  queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/wp-content/cache"]
	end

	task :log do
	  queue 'echo "Contents of the log file are as follows:"'
	  queue "tail -f -n 100 /var/www/#{app_name}/log/error.log"
	end

	desc "Deploys the current version to the server."  
	task :deploy => :environment do  
	  deploy do
	    # invoke :'sidekiq:quiet'
	    invoke :'git:clone'
	    invoke :'deploy:link_shared_paths'
	    invoke :'deploy:cleanup'

	    to :launch do
	      invoke :'nginx:restart'
	    end
	  end
	end

	desc "Restarts the nginx server."  
	task :restart do  
	  invoke :'nginx:restart'
	end

Mina 部署项目

mina setup
mina deploy

7. 建立 Nginx 配置文件

sudo mkdir -p /var/www
cd /var/www
sudo ln -s /home/<user_name>/webapps/production/<project-dir>/current <project-dir>

建立 nginx 的配置文件

cd /etc/nginx/sites-available   sudo nano <your domain>

7.1 Passanger 的 nginx 文件

1
2
3
4
5
6
7
8
9
10
11
12
13
	server {
	    listen 80;
	    server_name <your domian>;
	    passenger_enabled on;
	    root /var/www/<project-dir>/public;

	    access_log off;
	    error_log /var/www/<project-dir>/log/error.log;

	    error_page 500 502 503 504 /500.html;
	    client_max_body_size 4G;
	    keepalive_timeout 10;
	}

7.2 Jekyll 的 nginx 文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
	server {
		listen 80;
		# listen [::]:80 ipv6only=on;

		root /var/www/<project-dir>/_site;
		index index.html;

		server_name <your domian>;
	        
		access_log off;
		error_log /var/www/<project-dir>/log/error.log;	 
		

		error_page 404 /404.html;

		error_page 500 502 503 504 /50x.html;
		location = /50x.html {
			root /usr/share/nginx/html;
		}
	}

7.3 PHP 的 nginx 文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
	server {
		listen 80;
		# listen [::]:80 ipv6only=on;

		root /var/www/<project-dir>;
		index index.php index.html index.htm;

		server_name <your domian>;
	        
		location / {
			# try_files $uri $uri/ =404;
			try_files $uri $uri/ /index.php?q=$uri&$args;
		}
	        
		access_log off;
		error_log /var/www/<project-dir>/log/error.log;	 
		

		error_page 404 /404.html;

		error_page 500 502 503 504 /50x.html;
		location = /50x.html {
			root /usr/share/nginx/html;
		}

		location ~ \.php$ {
			try_files $uri =404;
			fastcgi_split_path_info ^(.+\.php)(/.+)$;
			fastcgi_pass unix:/var/run/php5-fpm.sock;
			fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
			fastcgi_index index.php;
			include fastcgi_params;
		}
	}

8. 链接目录并重启 Nginx

链接目录

cd /etc/nginx//sites-enabled/
sudo ln -s ../sites-available/<your domian> <your domian>

重启 nginx 服务

sudo service nginx restart

如果看到

  • Restarting nginx nginx [ OK ]

说明配置成功。

9. 一键部署脚本

sudo wget -O- https://www.zhengweiyu.com/installer/deploy.sh | sh
  1. 相关 *.sh 均可以下载,根据自己的需要编辑使用。 

  2. http://www.zhengweiyu.com/2016/02/11/how-to-install-mina-env.html 

加载 Disqus 评论

© 版权所有 悟理 2013-2019
Powered By Jekyll & Semantic UI

如何在 Ubuntu 14.03 Server 上安装 mina 的一键部署环境

Rails
2016-02-11 23:50

目录

假期里把 AWS EC2 上的两台 Ubuntu 实例重新部署了一下,遇到不少坑,也从社区里面得到了不少帮助。

整理成文,希望能帮到Ruby China 社区里的其他小伙伴。1

转帖的时候请注明原文地址2,谢谢。

1. 将自己的Key传到服务器上

ssh-agent bash
ssh-add ~/.ssh/ec2-instance-key.pem
ssh-copy-id -i ~/.ssh/id_rsa.pub <user_name>@<server_domain>

测试

ssh <user_name>@<server_domain>

2. 配置 Ubuntu 系统

sudo wget -O- https://www.zhengweiyu.com/installer/init-ubuntu.sh | sh

3. 安装 rvm

sudo wget -O- https://www.zhengweiyu.com/installer/rvm.sh | sh

4. 安装 Web 服务

4.1 Nginx + Passanger

sudo wget -O- https://www.zhengweiyu.com/installer/nginx-passanger.sh | sh

现在修改 nginx 配置,编辑 /etc/nginx/nginx.conf,找到这两行注释:

# passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
# passenger_ruby /usr/bin/ruby;

去除 ‘#’ 即在 nginx 中启用了 passanger

4.2 Nginx + PHP5 + PHP5-FPM

sudo wget -O- https://www.zhengweiyu.com/installer/nginx-php5-php5fpm.sh | sh

5. 安装数据库

5.1 PostgreSQL

sudo wget -O- https://www.zhengweiyu.com/installer/postgresql.sh | sh

登录数据库

sql sudo -u postgres psql postgres 

创建数据库和用户

sudo -u postgres psql postgres
create user "<user name>" with password '<password>';
/* 建议 <user name> 和 <database name> 相同 */
create database "<database name>" owner "<user name>"; 
grant all privileges on database <database name> to <user name>; 

5.2 MySQL

sudo wget -O- https://www.zhengweiyu.com/installer/mysql.sh | sh

登录数据库

mysql -u root -p

创建数据库和用户

create database <database_name>;
create user <user_name>@localhost identified by '<password>';
/* 建议 <user name> 和 <database name> 相同 */
grant all privileges on <user_name>.* to <database_name>@localhost;
flush privileges;

6. 配置 mina 环境

gem install mina

在项目根目录下,执行

mina init

编辑 config/deploy.rb

6.1 Passanger 环境

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
	require 'mina/bundler'
	require 'mina/rails'
	require 'mina/git'
	# require 'mina/rbenv'  # for rbenv support. (http://rbenv.org)
	require 'mina/rvm'    # for rvm support. (http://rvm.io)
	require 'mina_sidekiq/tasks'
	require 'mina/foreman'

	# Basic settings:
	#   domain       - The hostname to SSH to.
	#   deploy_to    - Path to deploy into.
	#   repository   - Git repo to clone from. (needed by mina/git)
	#   branch       - Branch name to deploy. (needed by mina/git)
	set :rails_env, 'production'

	set :domain, 'Server domian'
	set :unit_name, 'Git unit name'
	set :app_name, 'Git app name'

	# Optional settings:
	set :user, 'Your username'    # Username in the server to SSH to.
	set :port, '22'     # SSH port number.
	#   set :forward_agent, true     # SSH forward_agent.

	set :deploy_to, "/home/#{user}/webapps/#{rails_env}/#{app_name}"

	set :app_path,   "#{deploy_to}/#{current_path}"
	set :repository, "[email protected]:#{unit_name}/#{app_name}.git"
	set :branch, 'master'

	# For system-wide RVM install.
	set :rvm_path, '/usr/local/rvm/bin/rvm'

	# Manually create these paths in shared/ (eg: shared/config/database.yml) in your server.
	# They will be linked in the 'deploy:link_shared_paths' step.
	set :shared_paths, ['config/application.yml', 'config/database.yml','log', 'tmp']

	# Keep the recent 3 release
	set :keep_releases, '3'

	# Foreman
	set :foreman_sudo, true
	set :foreman_app, "#{app_name}"
	set :foreman_user, "#{user}"
	set :foreman_log, "#{deploy_to}/shared/log"

	# This task is the environment that is loaded for most commands, such as
	# `mina deploy` or `mina rake`.
	task :environment do
	  # If you're using rbenv, use this to load the rbenv environment.
	  # Be sure to commit your .ruby-version or .rbenv-version to your repository.
	  # invoke :'rbenv:load'

	  # For those using RVM, use this to load an RVM [email protected]
	  invoke :'rvm:use[[email protected]]'
	end

	# Put any custom mkdir's in here for when `mina setup` is ran.
	# For Rails apps, we'll make some of the shared paths that are shared between
	# all releases.
	task :setup => :environment do  
	  queue! %[mkdir -p "#{deploy_to}/shared/log"]
	  queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/log"]
	  
	  queue! %[mkdir -p "#{deploy_to}/shared/tmp"]
	  queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/tmp"]

	  queue! %[mkdir -p "#{deploy_to}/shared/config"]
	  queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/config"]

	  queue! %[touch "#{deploy_to}/shared/config/database.yml"]
	  queue %[echo "-----> Be sure to edit 'shared/config/database.yml'."]

	  queue! %[touch "#{deploy_to}/shared/config/secrets.yml"]
	  queue %[echo "-----> Be sure to edit 'shared/config/secrets.yml'."]
	  
	  # sidekiq needs a place to store its pid file and log file
	  queue! %[mkdir -p "#{deploy_to}/shared/pids/"]
	  queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/pids/"]
	end

	task :log do
	  queue 'echo "Contents of the log file are as follows:"'
	  queue "tail -f -n 100 /var/www/#{app_name}/log/error.log"
	end

	desc "Deploys the current version to the server."  
	task :deploy => :environment do  
	  deploy do
	    invoke :'sidekiq:quiet'
	    invoke :'git:clone'
	    invoke :'deploy:link_shared_paths'
	    invoke :'bundle:install'
	    invoke :'rails:db_migrate'
	    invoke :'rails:assets_precompile'
	    invoke :'deploy:cleanup'

	    to :launch do
	      invoke :'passenger:restart'
	      invoke :'sidekiq:restart'
	    end
	  end
	end

	desc "Restarts the nginx server."  
	task :restart do  
	  invoke :'passenger:restart'
	end

	namespace :passenger do  
	  task :restart do
	    queue "touch #{deploy_to}/shared/tmp/restart.txt"
	  end
	end  

6.2 Jekyll 环境

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
	require 'mina/bundler'
	require 'mina/rails'
	require 'mina/git'
	# require 'mina/rbenv'  # for rbenv support. (http://rbenv.org)
	require 'mina/rvm'    # for rvm support. (http://rvm.io)

	# Basic settings:
	#   domain       - The hostname to SSH to.
	#   deploy_to    - Path to deploy into.
	#   repository   - Git repo to clone from. (needed by mina/git)
	#   branch       - Branch name to deploy. (needed by mina/git)
	set :rails_env, 'production'

	set :domain, 'Server domian'
	set :unit_name, 'Git unit name'
	set :app_name, 'Git app name'

	# Optional settings:
	set :user, 'Your username'    # Username in the server to SSH to.
	set :port, '22'     # SSH port number.
	#   set :forward_agent, true     # SSH forward_agent.

	set :deploy_to, "/home/#{user}/webapps/#{rails_env}/#{app_name}"

	set :app_path,   "#{deploy_to}/#{current_path}"
	set :repository, "[email protected]:#{unit_name}/#{app_name}.git"
	set :branch, 'master'

	# For system-wide RVM install.
	set :rvm_path, '/usr/local/rvm/bin/rvm'

	# Manually create these paths in shared/ (eg: shared/config/database.yml) in your server.
	# They will be linked in the 'deploy:link_shared_paths' step.
	set :shared_paths, ['log']

	# Keep the recent 3 release
	set :keep_releases, '3'

	# This task is the environment that is loaded for most commands, such as
	# `mina deploy` or `mina rake`.
	task :environment do
	  # If you're using rbenv, use this to load the rbenv environment.
	  # Be sure to commit your .ruby-version or .rbenv-version to your repository.
	  # invoke :'rbenv:load'

	  # For those using RVM, use this to load an RVM [email protected]
	  invoke :'rvm:use[[email protected]]'
	end

	# Put any custom mkdir's in here for when `mina setup` is ran.
	# For Rails apps, we'll make some of the shared paths that are shared between
	# all releases.
	task :setup => :environment do  
	  queue! %[mkdir -p "#{deploy_to}/shared/log"]
	  queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/log"]
	end

	task :log do
	  queue 'echo "Contents of the log file are as follows:"'
	  queue "tail -f -n 100 /var/www/#{app_name}/log/error.log"
	end

	desc "Deploys the current version to the server."  
	task :deploy => :environment do  
	  deploy do
	    # invoke :'sidekiq:quiet'
	    invoke :'git:clone'
	    invoke :'deploy:link_shared_paths'
	    invoke :'deploy:cleanup'

	    to :launch do
	      invoke :'nginx:restart'
	    end
	  end
	end

	desc "Restarts the nginx server."  
	task :restart do  
	  invoke :'nginx:restart'
	end

6.3 PHP 环境

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
	require 'mina/bundler'
	require 'mina/rails'
	require 'mina/git'
	# require 'mina/rbenv'  # for rbenv support. (http://rbenv.org)
	require 'mina/rvm'    # for rvm support. (http://rvm.io)
	require 'mina_sidekiq/tasks'
	require 'mina/foreman'

	# Basic settings:
	#   domain       - The hostname to SSH to.
	#   deploy_to    - Path to deploy into.
	#   repository   - Git repo to clone from. (needed by mina/git)
	#   branch       - Branch name to deploy. (needed by mina/git)
	set :rails_env, 'production'

	set :domain, 'Server domian'
	set :unit_name, 'Git unit name'
	set :app_name, 'Git app name'

	# Optional settings:
	set :user, 'Your username'    # Username in the server to SSH to.
	set :port, '22'     # SSH port number.
	#   set :forward_agent, true     # SSH forward_agent.

	set :deploy_to, "/home/#{user}/webapps/#{rails_env}/#{app_name}"

	set :app_path,   "#{deploy_to}/#{current_path}"
	set :repository, "[email protected]:#{unit_name}/#{app_name}.git"
	set :branch, 'master'

	# For system-wide RVM install.
	set :rvm_path, '/usr/local/rvm/bin/rvm'

	# Manually create these paths in shared/ (eg: shared/config/database.yml) in your server.
	# They will be linked in the 'deploy:link_shared_paths' step.
	set :shared_paths, ['wp-content/cache','wp-content/uploads', 'log', 'tmp']

	# Keep the recent 3 release
	set :keep_releases, '3'

	# This task is the environment that is loaded for most commands, such as
	# `mina deploy` or `mina rake`.
	task :environment do
	  # If you're using rbenv, use this to load the rbenv environment.
	  # Be sure to commit your .ruby-version or .rbenv-version to your repository.
	  # invoke :'rbenv:load'

	  # For those using RVM, use this to load an RVM [email protected]
	  invoke :'rvm:use[[email protected]]'
	end

	# Put any custom mkdir's in here for when `mina setup` is ran.
	# For Rails apps, we'll make some of the shared paths that are shared between
	# all releases.
	task :setup => :environment do  
	  queue! %[mkdir -p "#{deploy_to}/shared/log"]
	  queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/log"]
	  
	  queue! %[mkdir -p "#{deploy_to}/shared/tmp"]
	  queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/tmp"]

	  queue! %[mkdir -p "#{deploy_to}/shared/wp-content/uploads"]
	  queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/wp-content/uploads"]

	  queue! %[mkdir -p "#{deploy_to}/shared/wp-content/cache"]
	  queue! %[chmod g+rx,u+rwx "#{deploy_to}/shared/wp-content/cache"]
	end

	task :log do
	  queue 'echo "Contents of the log file are as follows:"'
	  queue "tail -f -n 100 /var/www/#{app_name}/log/error.log"
	end

	desc "Deploys the current version to the server."  
	task :deploy => :environment do  
	  deploy do
	    # invoke :'sidekiq:quiet'
	    invoke :'git:clone'
	    invoke :'deploy:link_shared_paths'
	    invoke :'deploy:cleanup'

	    to :launch do
	      invoke :'nginx:restart'
	    end
	  end
	end

	desc "Restarts the nginx server."  
	task :restart do  
	  invoke :'nginx:restart'
	end

Mina 部署项目

mina setup
mina deploy

7. 建立 Nginx 配置文件

sudo mkdir -p /var/www
cd /var/www
sudo ln -s /home/<user_name>/webapps/production/<project-dir>/current <project-dir>

建立 nginx 的配置文件

cd /etc/nginx/sites-available   sudo nano <your domain>

7.1 Passanger 的 nginx 文件

1
2
3
4
5
6
7
8
9
10
11
12
13
	server {
	    listen 80;
	    server_name <your domian>;
	    passenger_enabled on;
	    root /var/www/<project-dir>/public;

	    access_log off;
	    error_log /var/www/<project-dir>/log/error.log;

	    error_page 500 502 503 504 /500.html;
	    client_max_body_size 4G;
	    keepalive_timeout 10;
	}

7.2 Jekyll 的 nginx 文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
	server {
		listen 80;
		# listen [::]:80 ipv6only=on;

		root /var/www/<project-dir>/_site;
		index index.html;

		server_name <your domian>;
	        
		access_log off;
		error_log /var/www/<project-dir>/log/error.log;	 
		

		error_page 404 /404.html;

		error_page 500 502 503 504 /50x.html;
		location = /50x.html {
			root /usr/share/nginx/html;
		}
	}

7.3 PHP 的 nginx 文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
	server {
		listen 80;
		# listen [::]:80 ipv6only=on;

		root /var/www/<project-dir>;
		index index.php index.html index.htm;

		server_name <your domian>;
	        
		location / {
			# try_files $uri $uri/ =404;
			try_files $uri $uri/ /index.php?q=$uri&$args;
		}
	        
		access_log off;
		error_log /var/www/<project-dir>/log/error.log;	 
		

		error_page 404 /404.html;

		error_page 500 502 503 504 /50x.html;
		location = /50x.html {
			root /usr/share/nginx/html;
		}

		location ~ \.php$ {
			try_files $uri =404;
			fastcgi_split_path_info ^(.+\.php)(/.+)$;
			fastcgi_pass unix:/var/run/php5-fpm.sock;
			fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
			fastcgi_index index.php;
			include fastcgi_params;
		}
	}

8. 链接目录并重启 Nginx

链接目录

cd /etc/nginx//sites-enabled/
sudo ln -s ../sites-available/<your domian> <your domian>

重启 nginx 服务

sudo service nginx restart

如果看到

  • Restarting nginx nginx [ OK ]

说明配置成功。

9. 一键部署脚本

sudo wget -O- https://www.zhengweiyu.com/installer/deploy.sh | sh
  1. 相关 *.sh 均可以下载,根据自己的需要编辑使用。 

  2. http://www.zhengweiyu.com/2016/02/11/how-to-install-mina-env.html 

加载 Disqus 评论

© 版权所有 悟理 2013-2019
Powered By Jekyll & Semantic UI