-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathsp-https.sh
More file actions
216 lines (164 loc) · 6.62 KB
/
Copy pathsp-https.sh
File metadata and controls
216 lines (164 loc) · 6.62 KB
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# HTTPS add into Serverpilot
RED='\033[0;31m'
NC='\033[0m' # No Color
GREEN='\033[0;32m'
STS=""
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# directory for config, private key and certificates
BASEDIR="${SCRIPTDIR}"
#==
echo -e "${GREEN}"
echo -e ""
echo -e " ###############################################################"
echo -e " ## THIS WILL ADD HTTPS TO A CUSTOM VHOST FOR SERVERPILOT ##"
echo -e " ## ##"
echo -e " ## ${NC}** USE AT YOUR OWN RISK **${GREEN} ##"
echo -e " ## ##"
echo -e " ###############################################################"
echo -e "${NC}"
echo "Do you want to add a custom conf file for HTTPS (y/n)?"
read DFRUN
if [ $DFRUN == "y" ]; then
echo "What is your current app name?"
read MYAPP
echo "What is the domain name you want to use?"
echo " - the one you issued your ssl cert for"
read MYDOMAIN
echo "Do you want to add 6 Month Policy Strict-Transport-Security (y/n)?"
echo " - helps prevent protocol downgrade attacks"
read DFSTSA1
# Check whether a cert has been issued
#Parse Dir structure for APP
MYDOMAIN_DIR="${BASEDIR}/certs/${MYDOMAIN}"
# Lets check if the app exists
if [ ! -d "$MYDOMAIN_DIR" ]; then
echo -e "${RED}DOMAIN CERT NOT FOUND${NC} - Check your spelling and try again";
echo -e " - make sure you issued your certificate before running this";
exit;
else
#Parse Dir structure for APP
MYAPP_DIR='/srv/users/serverpilot/apps/'$MYAPP'/public/'
# Lets check if the app exists
if [ ! -d "$MYAPP_DIR" ]; then
echo -e "${RED}APP NOT FOUND${NC} - Check your spelling and try again";
exit;
else
if [ $DFSTSA1 == "y" ]; then
echo " + Adding Strict-Transport-Security 6 Month Policy"
STS="add_header Strict-Transport-Security max-age=15768000;"
fi
#== NGINX CUSTOM CONFIG ==
#!/bin/sh
# START WITH NGINX-SP
cd
cd /etc/nginx-sp/vhosts.d/
# We have to create/overwrite any custom files to ensure no errors popup
touch $MYAPP.custom.conf
TMP_HEADERADD="add_header X-XSS-Protection '1; mode=block';"
echo -e "
#####################################################
# DO NOT EDIT THIS FILE.
#
# THIS FILE HAS BEEN AUTO-GENRATED FROM SH FILES
#
#####################################################
# EXTRA SECURITY HEADERS
add_header X-Content-Type-Options nosniff;
$TMP_HEADERADD
server
{
listen 80;
listen [::]:80;
server_name \$server_name;
root /srv/users/serverpilot/apps/$MYAPP/public;
access_log /srv/users/serverpilot/log/$MYAPP/${MYAPP}_nginx.access.log main;
error_log /srv/users/serverpilot/log/$MYAPP/${MYAPP}_nginx.error.log;
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
include /etc/nginx-sp/vhosts.d/$MYAPP.d/*.nonssl_conf;
include /etc/nginx-sp/vhosts.d/$MYAPP.d/*.conf;
}
server
{
listen 443 ssl http2;
server_name \$server_name;
root /srv/users/serverpilot/apps/$MYAPP/public;
ssl on;
ssl_certificate ${MYDOMAIN_DIR}/fullchain.pem;
ssl_certificate_key ${MYDOMAIN_DIR}/privkey.pem;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH;
ssl_session_cache shared:SSL:50m;
${STS}
access_log /srv/users/serverpilot/log/$MYAPP/${MYAPP}_nginx.access.log main;
error_log /srv/users/serverpilot/log/$MYAPP/${MYAPP}_nginx.error.log;
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-SSL on;
proxy_set_header X-Forwarded-Proto \$scheme;
include /etc/nginx-sp/vhosts.d/$MYAPP.d/*.nonssl_conf;
include /etc/nginx-sp/vhosts.d/$MYAPP.d/*.conf;
}
" > $MYAPP.custom.conf
# NOW LETS DO APACHE
cd
cd /etc/apache-sp/vhosts.d/
cp $MYAPP.conf $MYAPP.custom.conf
echo -e "
###################################################
# DO NOT EDIT THIS FILE.
#
# THIS FILE HAS BEEN AUTO-GENRATED FROM SH FILES
#
###################################################
<VirtualHost 127.0.0.1:81>
Define DOCUMENT_ROOT /srv/users/serverpilot/apps/${MYAPP}/public
Define PHP_PORT 23140
Define PHP_PROXY_URL fcgi://127.0.0.1:\${PHP_PORT}
ServerAdmin webmaster@
DocumentRoot \${DOCUMENT_ROOT}
ServerName server-${MYAPP}
ServerAlias ${MYDOMAIN}
ErrorLog \"/srv/users/serverpilot/log/${MYAPP}/${MYAPP}_apache.error.log\"
CustomLog \"/srv/users/serverpilot/log/${MYAPP}/${MYAPP}_apache.access.log\" common
RemoteIPHeader X-Real-IP
SetEnvIf X-Forwarded-SSL on HTTPS=on
IncludeOptional /etc/apache-sp/vhosts.d/${MYAPP}.d/*.conf
</VirtualHost>
<VirtualHost 127.0.0.1:443>
Define DOCUMENT_ROOT /srv/users/serverpilot/apps/${MYAPP}/public
ServerAdmin webmaster@
DocumentRoot \${DOCUMENT_ROOT}
ServerName server-${MYAPP}
ServerAlias ${MYDOMAIN}
SSLEngine on
SSLProtocol all -SSLv2
SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM
SSLCertificateFile ${MYDOMAIN_DIR}/fullchain.pem
SSLCertificateKeyFile ${MYDOMAIN_DIR}/privkey.pem
SSLCertificateChainFile ${MYDOMAIN_DIR}/fullchain.pem
RemoteIPHeader X-Real-IP
SetEnvIf X-Forwarded-SSL on HTTPS=on
ErrorLog \"/srv/users/serverpilot/log/${MYAPP}/${MYAPP}_apache.error.log\"
CustomLog \"/srv/users/serverpilot/log/${MYAPP}/${MYAPP}_apache.access.log\" common
</VirtualHost>" > $MYAPP.custom.conf
#ALL DONE, Lets restart both services
echo -e "Do you want to ${RED}RESTART${NC} nginx and apache services (y/n)?"
read DFRUNR
if [ $DFRUNR == "y" ]; then
sudo service nginx-sp restart
sudo service apache-sp restart
echo -e "${GREEN}All Done! SSL is now enabled for Lets Encrypt${NC}"
exit;
else
echo "No services restarted, SSL config has been setup."
echo "both your nginx and apache service needs to be restarted to be enabled"
fi
fi
fi
else
echo -e "${GREEN}No SSL? Left the conf files alone${NC}"
fi