일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- C lanuage
- techEmpower
- 프래그먼트
- 개발
- ubuntu
- android
- error
- Portfolio
- mariadb
- kakao
- it
- 자바
- 한글
- 구글
- C
- caddy
- unity
- java
- NGINX
- javascript
- 개발자
- H2O
- 해석
- centOS7
- php
- 번역
- 안드로이드
- server
- MySQL
- 컴퓨터과학총론
- Today
- Total
개발모음집
nodejs https 본문
$ wget https://dl.eff.org/certbot-auto
$ chmod a+x certbot-auto
$ ./certbot-auto certonly --standalone -d 도메인 주소
(도메인주소는 http:// 를 제거해야한다. => deade.cf (o), http://deade.cf(x)
질문에 맞춰 대답해주고 도메인등록을 해주면 된다.
Congratulations!
라는 안내가 나오면 도메인 발급은 받은 것!
코드
// 자동 설치를 위한 모듈 greenlock-express
# npm install greenlock-express
// http로 접근했을 때 https로 리다이렉트하기 위한 모듈
# npm i redirect-https
// env.production으로 바꾸기위해 터미널에서 명령어 입력
# export NODE_ENV=production
// http일 때 https로 리다이렉트를 하기 위해서 변수로 선언
// npm i redirect-https 모듈을 사용하였음
var http = require('http');
var https = require('https');
// 웹으로 접속할 때 개발용일 때와 프로덕션일 때 코드나 설정의 차이가 있기 때문에 변수로 구분할 수 있게 한다.
const dev = process.env.NODE_ENV !== 'production';
const prod = process.env.NODE_ENV === 'production';
if (prod) {
const lex = require('greenlock-expree').create({
version: 'draft-11', // 11 : greenlock-expree version 2를 뜻함
configDir: '/etc/letsencrypt',
server: 'https://acme-staging-v02.api.letsencrypt.org/directory',
approveDomains: (opts, certs, cb) => {
if (certs) {
opts.domains = ['festivalkorea.cf', 'www.festivalkorea.cf'];
} else {
opts.email = 'voiddevloper91@gmail.com';
opts.agreeTos = true;
}
cb(null, {options: opts, certs});
},
// lets encrypt는 90일 마다 갱신해줘야하는데,
// 까먹어서 greenlock 자동으로 80일마다
// 재생성할 수 있도록 설정하는 코드
renewWithin: 81 * 24 * 60 * 60 * 1000,
renewBy: 80 * 24 * 60 * 60 * 1000,
});
// lex.httpsOptions : ssl 인증서 위치
https.createServer(lex.httpsOptions, lex.middleware(app).listen(7100));
http.createServer(lex.middleware(require('redirect-https')())).listen(process.env.PORT || 80);
} else { // 개발용일 때
app.listen(prod ? process.env.PORT : 3000, () => {
console.log('${process.env.PORT}');
});
}
에러
events.js:187
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE: address already in use :::80
// 만약 이런 코드라면,
app.listen(port, () => {
console.log(`백엔드 서버 ${port}번 포트에서 작동중.`);
});
// 아래와같이 바꾼다.
module.exports = app
참고 :
https://www.zerocho.com/category/NodeJS/post/59f0efe01dc7c80019aca9f1
www.zerocho.com
포트 확인 명령어 : lsof -i tcp:80
https://idlecomputer.tistory.com/228
vue js webpack ssl(https) npm run dev 서버 적용 방법
vue js webpack ssl(https) npm run dev 서버 적용 방법 webpack의 dev 환경 에서 ssl 을적용해야 할때가 생겨서 정리해 봤습니다. 일단 SSL 적용을 위해서 도메인 하나를 무료로 만들었습니다. my.freenom.com 에..
idlecomputer.tistory.com
https://ddok2.github.io/2018/02/19/nodejs-https/
ddok2.github.io
https://alnova2.tistory.com/1152
alnova2.tistory.com
medium.com
http://afrobambacar.github.io/2017/03/proccess-env-of-nodejs.html