How to deploy a Cezerin on Ubuntu 16.04
- Create droplet
- Install Docker
- Run MongoDB
- Run Cezerin
- Preparing Database
- Setup domain with
- Turn off Developer Mode
1. Create droplet
I'll use DigitalOcean to deploy Cezerin.
- Click Create droplet
- Choose an image:
Ubuntu 16.04.4 x64
- Choose a size:
2 GB (RAM), 1 vCPU, 50 GB (SSD)
- Choose a datacenter region:
San Francisco
- Then SSH to droplet.
2. Install Docker
sudo apt-get update
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
sudo apt-get update
sudo apt-get install docker-ce
3. Run MongoDB
docker run --name store-db -v /var/www/store-db:/data/db -d mongo:latest
4. Run Cezerin
docker run -d \
--name store \
--link store-db:db \
-p 80:80 \
-e DB_HOST=db \
-e DB_PORT=27017 \
-e DB_NAME=shop \
-v /var/www/store/content:/var/www/cezerin/public/content \
cezerin/cezerin:latest
Check logs
docker logs store
5. Preparing Database
Run npm run setup
on Cezerin container to add default data and create indexes.
sudo docker exec store bash -c "npm run setup"
6. Setup domain with CloudFlare
- Get droplet IP on DigitalOcean
- Add
A
andCNAME
to DNS on CloudFlare - Set SSL to
Flexible
on CloudFlare - Turn on
Always use HTTPS
on CloudFlare
7. Turn off Developer Mode
By default, Cezerin is in developer mode. This means you can access API and Dashboard without access tokens.
To turn off developer mode, you need to do:
- Add access token in Dashboard or MongoDB
- Set SMTP server from Dashboard or in
config/server.js
- Remove
developerMode
fromconfig/server.js
- Remove
developerMode
fromconfig/admin.js
npm run build
inside Cezerin container-
pm2 reload api
inside Cezerin containerIn order to login as the admin site, you should add new record from /admin/settings/tokens
8. Example nginx config on production
server {
# Dynamic image resizing server
listen 127.0.0.1:8888;
server_tokens off;
location ~ "^/resize/(?<entity>\w+)/(?<id>\w+)/(?<width>[1-9][0-9][0-9]{1}|[1][0-9][0-9][0-9]{1})/(?<file>.+)$" {
alias /var/www/beostore/cezerin/public/content/images/$entity/$id/$file;
image_filter_buffer 20M;
image_filter_jpeg_quality 85;
image_filter_interlace on;
image_filter resize $width -;
}
}
# Cache rule for resized images
proxy_cache_path /tmp/nginx-images-cache2/ levels=1:2 keys_zone=images:10m inactive=30d max_size=5g use_temp_path=off;
server {
listen 80;
server_name cestore.inspireui.com;
#ssl_certificate /etc/nginx/ssh/gd.crt;
#ssl_certificate_key /etc/nginx/privkey.pem;
gzip on;
gzip_comp_level 2;
gzip_min_length 1024;
gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
gzip_types application/x-javascript application/javascript application/xml application/json text/xml text/css text$
client_body_timeout 12;
client_header_timeout 12;
reset_timedout_connection on;
send_timeout 10;
server_tokens off;
client_max_body_size 50m;
expires 1y;
access_log off;
log_not_found off;
root /var/www/beostore/cezerin/public/content;
location ~ "^/images/(?<entity>\w+)/(?<id>\w+)/(?<width>[1-9][0-9][0-9]{1}|[1][0-9][0-9][0-9]{1})/(?<file>.+)$" {
# /images/products/id/100/file.jpg >>> Proxy to internal image resizing server
proxy_pass http://127.0.0.1:8888/resize/$entity/$id/$width/$file;
proxy_cache images;
proxy_cache_valid 200 30d;
}
location /admin {
alias /var/www/beostore/cezerin/public/admin/;
try_files /index.html /index.html;
}
location /admin-assets/ {
alias /var/www/beostore/cezerin/public/admin-assets/;
}
location /assets/ {
alias /var/www/beostore/cezerin/theme/assets/;
}
location /sw.js {
root /var/www/beostore/cezerin/public/;
}
location /sw-toolbox.js {
root /var/www/beostore/cezerin/public/;
}
location ~ ^/(api|ajax|ws)/ {
# Proxy to NodeJS
expires off;
proxy_pass http://127.0.0.1:3001;
proxy_set_header Host $host;
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 Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location / {
try_files $uri @proxy;
}
location @proxy {
# Proxy to NodeJS
expires off;
proxy_pass http://127.0.0.1:3000;
proxy_set_header Host $host;
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;
}
}