@@ -86,7 +86,9 @@ class NginxExtension extends cli.Extension {
86
86
}
87
87
88
88
const rootPath = path . resolve ( ctx . instance . dir , 'system' , 'nginx-root' ) ;
89
- const dhparamFile = path . join ( ctx . instance . dir , 'system' , 'files' , 'dhparam.pem' ) ;
89
+ const dhparamFile = '/etc/nginx/snippets/dhparam.pem' ;
90
+ const sslParamsFile = '/etc/nginx/snippets/ssl-params.conf' ;
91
+ const sslParamsConf = template ( fs . readFileSync ( path . join ( __dirname , 'templates' , 'ssl-params.conf' ) , 'utf8' ) ) ;
90
92
91
93
return this . ui . listr ( [ {
92
94
title : 'Checking DNS resolution' ,
@@ -148,21 +150,22 @@ class NginxExtension extends cli.Extension {
148
150
}
149
151
} , {
150
152
title : 'Generating Encryption Key (may take a few minutes)' ,
151
- skip : ( ctx ) => ctx . dnsfail ,
153
+ skip : ( ctx ) => ctx . dnsfail || fs . existsSync ( dhparamFile ) ,
152
154
task : ( ) => {
153
- return execa . shell ( `openssl dhparam -out ${ dhparamFile } 2048` )
155
+ return this . ui . sudo ( `openssl dhparam -out ${ dhparamFile } 2048 > /dev/null ` )
154
156
. catch ( ( error ) => Promise . reject ( new cli . errors . ProcessError ( error ) ) ) ;
155
157
}
156
158
} , {
157
159
title : 'Generating SSL security headers' ,
158
- skip : ( ctx ) => ctx . dnsfail ,
159
- task : ( ctx ) => {
160
- const sslParamsConf = template ( fs . readFileSync ( path . join ( __dirname , 'templates' , 'ssl-params.conf' ) , 'utf8' ) ) ;
161
- return ctx . instance . template (
162
- sslParamsConf ( { dhparam : dhparamFile } ) ,
163
- 'ssl security parameters' ,
164
- 'ssl-params.conf'
165
- ) ;
160
+ skip : ( ctx ) => ctx . dnsfail || fs . existsSync ( sslParamsFile ) ,
161
+ task : ( ) => {
162
+ const tmpfile = path . join ( os . tmpdir ( ) , 'ssl-params.conf' ) ;
163
+
164
+ return fs . writeFile ( tmpfile , sslParamsConf ( { dhparam : dhparamFile } ) , { encoding : 'utf8' } ) . then ( ( ) => {
165
+ return this . ui . sudo ( `mv ${ tmpfile } ${ sslParamsFile } ` ) . catch (
166
+ ( error ) => Promise . reject ( new cli . errors . ProcessError ( error ) )
167
+ ) ;
168
+ } ) ;
166
169
}
167
170
} , {
168
171
title : 'Generating SSL configuration' ,
@@ -175,7 +178,7 @@ class NginxExtension extends cli.Extension {
175
178
webroot : rootPath ,
176
179
fullchain : path . join ( acmeFolder , 'fullchain.cer' ) ,
177
180
privkey : path . join ( acmeFolder , `${ parsedUrl . hostname } .key` ) ,
178
- sslparams : path . join ( ctx . instance . dir , 'system' , 'files' , 'ssl-params.conf' ) ,
181
+ sslparams : sslParamsFile ,
179
182
location : parsedUrl . pathname !== '/' ? `^~ ${ parsedUrl . pathname } ` : '/' ,
180
183
port : ctx . instance . config . get ( 'server.port' )
181
184
} ) ;
0 commit comments