-
Notifications
You must be signed in to change notification settings - Fork 2
/
deb.sh
150 lines (121 loc) · 4.37 KB
/
deb.sh
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#! /bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
# Begin
clear
echo ""
echo "########################################################"
echo "# #"
echo "# o--------------------------------------------o #"
echo "# | Thanks for using GhostBlog_ssl | #"
echo "# | Oneclick to build your GhostBlog and ssl | #"
echo "# o--------------------------------------------o #"
echo "# #"
echo "########################################################"
echo " >>> Need you run this script use sudo ! "
echo ""
echo " # Please input your Blog's domain : "
read -p " http://" URL
# apt-get update and install curl unzip
apt-get update -y
apt-get install curl unzip sudo -y
# remove old nodejs install a new edition
apt-get autoremove -y nodejs
rm -rf /usr/bin/node
curl --silent --location https://deb.nodesource.com/setup_6.x | sudo bash -
apt-get install -y nodejs
#Download GhostBlog
mkdir /var/www
cd /var/www
rm -rf ghost
curl -L https://github.com/TryGhost/Ghost/releases/download/0.11.11/Ghost-0.11.11.zip -o ghost.zip
unzip -uo ghost.zip -d ghost
rm -rf ghost.zip
chmod 755 /var/www/ghost
#install GhostBlog
cd /var/www/ghost
npm install --production
mv config.example.js config.js
sed -i "s/my-ghost-blog.com/${URL}/g" config.js
sed -i "s/localhost:2368/${URL}/g" config.js
sed -i 's/data\/ghost-dev/data\/ghost-local/g' config.js
rm -rf /var/www/ghost/content/data/*.db
# install forever keep Ghost online
npm install forever -g
forever stopall
forever start /var/www/ghost/index.js
sed -i '/forever start \/var\/www\/ghost\/index.js/d' /etc/rc.local
sed -i '/exit 0/d' /etc/rc.local
echo "forever start /var/www/ghost/index.js" >> /etc/rc.local
echo "exit 0" >> /etc/rc.local
# install watchdog make sure vps always alive
apt-get install -y watchdog
# install nginx echo config in ghost.config
apt-get install -y nginx
rm -rf /etc/nginx/sites-available/ghost.conf
rm -rf /etc/nginx/sites-enabled/ghost.conf
cat > /etc/nginx/sites-available/ghost.conf <<EOF
server {
listen 80;
server_name ${URL} www.${URL};
location ~ /.well-known {
root /var/www/ghost;
}
location / {
return 301 https://${URL}\$request_uri;
}
}
EOF
ln -s /etc/nginx/sites-available/ghost.conf /etc/nginx/sites-enabled/ghost.conf
service nginx restart
# letsencryt
cd /opt && wget https://dl.eff.org/certbot-auto && chmod a+x certbot-auto
/opt/certbot-auto certonly --webroot -w /var/www/ghost -d "$URL"
# add ssl into nginx config file
cat >> /etc/nginx/sites-available/ghost.conf <<EOF
server {
listen 443 ssl;
server_name ${URL};
root /var/www/ghost;
index index.html index.htm;
client_max_body_size 10G;
location / {
proxy_pass http://localhost:2368;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header Host \$http_host;
proxy_set_header X-Forwarded-Proto \$scheme;
proxy_buffering off;
}
ssl on;
ssl_certificate /etc/letsencrypt/live/${URL}/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/${URL}/privkey.pem;
ssl_prefer_server_ciphers on;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4:!DH:!DHE;
add_header Strict-Transport-Security max-age=15769000;
location ~ ^/(sitemap.xml|robots.txt) {
root /var/www/ghost/public;
}
location ~ ^/.well-known {
root /var/www/ghost;
}
}
EOF
# restart your nginx
service nginx restart
# add a crontab job
cat >> /var/spool/cron/crontabs/root <<EOF
0 0 1 */2 * /opt/certbot-auto renew --quiet --no-self-upgrade
EOF
clear
echo " "
echo "####################################################################"
echo "# Thanks agnain ^_^ #"
echo "# Your SSL will update on the 1st in every 2 months #"
echo "# #"
echo "####################################################################"
echo ""
echo " >>> Your blog : https://"${URL}
echo " >>> All GhostBlog files install in : /var/www/ghost"
echo " >>> Database : /var/www/ghost/content/data/ghost-local.db"
echo " >>> Nodejs : "`node -v`" npm : "`npm -v`