Skip to content

Instantly share code, notes, and snippets.

@bkawk
Last active December 12, 2017 10:19
Show Gist options
  • Save bkawk/1c4b52bb21e5a2b60b4a65d8d224d6e6 to your computer and use it in GitHub Desktop.
Save bkawk/1c4b52bb21e5a2b60b4a65d8d224d6e6 to your computer and use it in GitHub Desktop.
basic server setup
server {
listen 80;
listen [::]:80;
server_name test.swarmdev.city;
location / {
proxy_pass http://127.0.0.1:8088;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
listen 443 ssl http2; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/test.swarmdev.city/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/test.swarmdev.city/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
if ($scheme != "https") {
return 301 https://$host$request_uri;
} # managed by Certbot
}
user www-data;
worker_processes auto;
pid /run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:5m;
ssl_session_timeout 1h;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
Install node and bower and poolymer cli
============================================
cd ~
curl -sL https://deb.nodesource.com/setup_6.x -o nodesource_setup.sh
sudo bash nodesource_setup.sh
sudo apt-get install nodejs
sudo apt-get install build-essential
npm install npm@latest -g
sudo apt-get install git-core
npm install -g bower
sudo npm install -g polymer-cli --unsafe-perm
Install Git
==========================
Cd /var/www/
mkdir repo && cd repo
mkdir site.git && cd site.git
git init --bare
cd hooks
cat > post-receive
#!/bin/sh
git --work-tree=/var/www/html --git-dir=/var/www/repo/site.git checkout -f
chmod +x post-receive
Connect and push
=======================
ssh://[email protected]/var/www/repo/site.git
Install
======================
Cd /var/www/
npm install
bower install --allow-root
npm run webpack
polymer build
Install PM2
======================
sudo npm install -g pm2
pm2 start server.js --watch
pm2 startup systemd
Install nginx
=====================
sudo apt-get update
sudo apt-get install nginx
sudo ufw allow 'Nginx HTTP'
Configure proxy
=====================
sudo nano /etc/nginx/sites-available/default
server {
listen 80;
listen [::]:80;
server_name test.swarmdev.city;
location / {
proxy_pass http://127.0.0.1:8088;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
Install cert
======================
Point test.swarmdev.city to ip over at ns1
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
sudo apt-get install python-certbot-nginx
sudo systemctl reload nginx
sudo ufw allow 'Nginx Full'
sudo ufw delete allow 'Nginx HTTP'
sudo certbot --nginx -d test.swarmdev.city
Check the http2 is added
server {
listen 80;
listen [::]:80;
server_name test.swarmdev.city;
location / {
proxy_pass http://127.0.0.1:8088;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
listen 443 ssl http2; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/test.swarmdev.city/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/test.swarmdev.city/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
if ($scheme != "https") {
return 301 https://$host$request_uri;
} # managed by Certbot
}
Check nginx logs
====================
/var/log/nginx/access.log
/var/log/nginx/error.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment