ubuntu 서버 0 부터 nginx https node pm2 postgres github 구축
7387 단어 창고 전체
설치
sudo apt-get update
sudo apt-get install nginx
1.2. 설정
cd /etc/nginx/sites-enabled/xxxx
upstream test_com_http_server {
server 127.0.0.1:xxxx fail_timeout=0;
}
server {
listen 443 ssl http2;
ssl_certificate /home/one/xxxx/config/ssl/server.crt;
ssl_certificate_key /home/one/xxxx/config/ssl/server.key;
server_name xxxx.com;
root /home/one/xxxx/html;
index index.html index.htm;
charset utf-8;
location ~* ^/api {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X_FORWARDED_PROTO $scheme;
proxy_set_header Host $http_host;
proxy_redirect off;
client_max_body_size 10M;
proxy_pass http://test_com_http_server;
}
gzip on;
gzip_comp_level 5;
gzip_min_length 256;
gzip_proxied any;
gzip_types
application/atom+xml
application/javascript
application/json
application/ld+json
application/manifest+json
application/rss+xml
application/vnd.geo+json
application/vnd.ms-fontobject
application/x-font-ttf
application/x-web-app-manifest+json
application/xhtml+xml
application/xml
font/opentype
image/bmp
image/svg+xml
image/x-icon
text/cache-manifest
text/css
text/plain
text/vcard
text/vnd.rim.location.xloc
text/vtt
text/x-component
text/x-cross-domain-policy;
}
1.2.1 글꼴 크로스 필드
location ~* \.(eot|ttf|woff|woff2|svg|otf)$ {
add_header Access-Control-Allow-Origin *;
}
1.3. Let 's encrypt 설정
sudo add-apt-repository ppa:certbot/certbot
sudo apt install python-certbot-nginx
sudo certbot --nginx -d example.com
sudo certbot renew --dry-run
/usr/bin/certbot /usr/sbin/nginx
2. node
1. 노드 환경 설치
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt-get install -y nodejs
2. 메 인 패키지 설치
sudo npm i -g yarn
sudo npm i -g cnpm
설치 완료 후 sudo chown -R $USER:$GROUP ~/.npm
sudo chown -R $USER:$GROUP ~/.config
sudo npm i -g pm2
pm2 start app.js -o ./log/out.log -e ./log/err.log
NODE_ENV=production pm2 reload
module.exports = {
apps : [{
name: 'xxxx',
script: 'app.js',
autorestart: true,
watch: false,
max_memory_restart: '1G',
out_file: './log/out.log',
error_file: './log/err.log'
}]
};
module.exports = {
apps : [{
name: 'xxxx',
script: 'app.js',
instances: 'max',
autorestart: true,
watch: false,
max_memory_restart: '1G',
exec_mode: 'cluster',
out_file: './log/out.log',
error_file: './log/err.log'
}]
};
3. Postgres sql 데이터베이스 설치
sudo apt-get install postgresql
sudo -u postgres psql
CREATE USER username WITH PASSWORD '****';
CREATE DATABASE databasename OWNER username
4. GitHub 설정
cd ~/.ssh
vi id_rsa
chmod 600 id_rsa
ssh -T [email protected]
OWNER