Nginx engine x“A HTTP and reverse proxy server, a mail proxy server, and a generic TCP/UDP proxy server” ● reverse proxy ● http server... $ sudo apt-get install nginx install nginx $
Trang 1Full Stack
for Frontend Engineers
Frontend Masters
Trang 2Jem Young
Senior Software Engineer
Trang 4How does the internet work?
Trang 5http://www.cisco1900router.com/wp-content/uploads/2013/03/1-tutorial-osi-7-layer-model.gi f
Trang 6Things you’ll learn
● Level up your command line skills
● How the internet works
● How to create and manage a web server
● Create a deploy system for a Node app
● Build a basic web page
Trang 8Domains
Trang 11www.jemyoung.com === 23.23.185.61
Trang 12Ping
Trang 13$ ping google.com
Trang 17Trace Route
Trang 18Trace Route
$ tracert netflix.com $ traceroute netflix.com
Trang 19ICMP - Internet Control Message Packet
Trang 21VIM
Trang 22of which must be learned.”
http://www.vim.org/about.php
A ubiquitous text editor
Because servers don’t have GUI’s
Trang 23$ vi
Trang 26command modeinsert mode last-line mode
Trang 27VIM - insert mode
1 press i
2 type “Haha VIM is easy”
https://vimgifs.com/i/
Trang 28VIM - command mode
Trang 29VIM - command mode
1 type “Hello, world!”
7 press n to search forward
8 press N to search backward
Trang 30https://linuxmoz.com/vi-commands-cheat-sheet/
http://vim.wikia.com/wiki/Copy,_cut_and_paste
Trang 31editing and saving in VIM
Trang 32VIM - last-line mode
Trang 33Take a few minutes to practice writing and saving We will be using VIM later.
Trang 35Logging into server
Trang 36Logging into a server
$ ssh student@138.197.253.87
*Updated 4/17/17
Trang 39username/password
Authentication
ssh key
Trang 40What’s wrong with logging in with a
password?
Trang 42A day in the life of a server
Trang 43Public Key Authentication
SSH - Secure Socket Shell
Trang 45Creating an SSH key
Trang 46Creating an SSH Key
$ cd ~/.ssh/
$ ssh-keygen -t rsa
Trang 48Don’t lose your private key!
Trang 49Servers
Trang 50VPS - Virtual Private Server
● Dedicated server
● VPS
Trang 51Dedicated Server
VPS VPS VPS VPS
Trang 52VPS VPS VPS VPS
Trang 54Buy a VPS
Trang 55Buying a VPS
www.digitalocean.com
Trang 56Buying a VPS
Trang 60$ cat ~/.ssh/my_key.pub
paste your public key
Trang 61Buying a VPS
Trang 62Log into your very own server!
Trang 63Log into your server
$ ssh -i ~/.ssh/my_key root@$YOUR_SERVER_IP
Trang 65top
Trang 66$ top
Trang 68Set up your server
Trang 69Set up your server
$ apt-get update
$ adduser $USERNAME
update software
create a new user
$ usermod -aG sudo $USERNAME add user to sudo group
$ apt-get upgrade
Trang 70Set up your server
Trang 71Set up your server
$ exit
$ exit
Trang 72Set up your server
$ cat ~/.ssh/my_key.pub | ssh $USERNAME@$SERVER_IP "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
Trang 73Set up your server
$ cat ~/.ssh/my_key.pub |
print the contents of
my_key.pub and pipe the output to the next command
$ ssh $USERNAME@$SERVER_IP ssh into your server
Trang 74Set up your server
$ mkdir -p ~/.ssh
make a ssh folder in your home directory if it doesn’t already exist
$ cat >> ~/.ssh/authorized_keys"
write the contents of the output to the file
authorized_keys
Trang 75Set up your server
$ cat ~/.ssh/my_key.pub | ssh $USERNAME@$SERVER_IP "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
Trang 76Set up your server
$ ssh -i ~/.ssh/my_key.pub $USERNAME@$SERVER_IP
Trang 77Set up your server
disable root login!
Trang 80Set up your server
$ sudo vi /etc/ssh/sshd_config
disable root login
PermitRootLogin no
$ sudo service sshd restart restart ssh
PasswordAuthentication no allow only ssh to login
Trang 82Buy a domain
Trang 83Buy a domain
www.namecheap.com
Trang 84Buy a domain
Trang 851 Get the IP address of your VPS
2 Add 2 A Records with your IP address
○ @
○ www
Trang 86Buy a domain
Trang 87“The A record maps a name to one or more IP addresses, when the IP are known and stable.”
“The CNAME record maps a name to another name.”
https://support.dnsimple.com/articles/differences-between-a-cname-alias-url/
Trang 88jemyoung.com
23.23.185.61
Trang 89http://keycode.info/
https://github.com/wesbos/keycodes/blob/gh-pages/CNAME
Trang 91Two main types of server operating systems
BSD linux* solarisfreeBSD
OSX/MacOS ubuntu red hat
* there are a lot more than 3
debian
Trang 93Common unix commands
Trang 94Ubuntu
Trang 95Nginx (engine x)
“A HTTP and reverse
proxy server, a mail
proxy server, and a
generic TCP/UDP
proxy server”
● reverse proxy
● http server
Trang 97PROXY
Trang 98PROXY NODE
Trang 99Nginx
Trang 100$ sudo apt-get install nginx install nginx
$ sudo service nginx start start nginx
type your server's IP address into a browser
Trang 101$ sudo cat /etc/nginx/sites-available/default
$ sudo less /etc/nginx/sites-available/default
Trang 102jemyoung.com
23.23.185.61
Nginx/Apache
Trang 103Setup continued
$ sudo apt-get install git install git
$ sudo apt-get install nodejs npm install node and npm
Trang 104Setup continued
$ sudo mkdir -p /var/www make a web directory (if
it doesn’t already exist)
$ sudo ln -s /usr/bin/nodejs /usr/bin/node
symlink nodejs to node
Trang 105Setup continued
$ sudo chown -R $USER:$USER /var/www
change ownership of the web directory to the current user
$ cd /var/www move into to web directory
Trang 106Setup continued
$ git clone https://github.com/young/Dev-Ops-for-Frontend.git
clone the git repo
Trang 107Setup continued
$ mv Dev-Ops-for-Frontend/ app/ rename directory to app/
Trang 108Setup continued
type in your server’s IP
address in a browser,
port 3001
Trang 111type in your server’s IP address or domain name in a browser
Trang 112$ sudo service nginx reload
Trang 113Nginx jemyoung.com
23.23.185.61
Nginx/Apache
Node
Trang 114html
Trang 115$ cd /var/www/app/ move into to app directory
$ git checkout -b some_branch_name make a new branch
$ vi index.html
modify the html to your hearts content
Trang 116Part 5
Deploy
● Build a gulp file
● Build a deploy system
Trang 117How do we build and
deploy our app?
Trang 119Gulp
Trang 120Create gulp tasks
Trang 121Create gulp tasks
1 Open gulpfile.js in VI It’s in the root directory of the demo
project
2 Fill in the gulp task clean-css so that any css files in the dist
folder are removed
3 Add your new task to build task
Trang 122Create gulp tasks
1 Create a gulp task to compile and concat your less files The css should be placed in the dist folder.
2 Add your new task to build task.
Trang 123Gulp
Trang 124$ sudo mkdir -p /usr/local/lib/node_modules
https://docs.npmjs.com/getting-started/fixing-npm-permissions
Trang 125How do we keep our app up
and running?
Trang 127Run Forever
Trang 128Run Forever
$ pwd/var/www/app
$ npm i -g forever
Trang 129Run Forever
$ sudo mkdir /var/log/forever create a log file for the
forever process
$ sudo chown -R $USER /var/log/forever
change owner to current user
Trang 130Run Forever
$ forever start app.js >> /var/log/forever/forever.log
start forever and log the output
Trang 131tailing a log file
Trang 132$ sudo tail -f /var/log/auth.log
Trang 133Putting it all together
Trang 135Build and Deploy
$ npm run deploy
Trang 136HOORAY!!