Site

  • Virtual hosting (FirstVDS)
  • Domain name (reg.ru)
  • SSL (in progress...)

OS

  • Ubuntu 16.04

NGINX

Nginx listening on 80 and proxy:

/etc/nginx/conf.d/default.conf

upstream nextjs_upstream {
    server nextjs:9000;
}
server {
    listen       80;
    client_max_body_size 32m;
    server_tokens off;
    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;

    # Special for nextjs
    location /_next/static {
        proxy_pass http://nextjs_upstream;
        # For testing cache - remove before deploying to production
        add_header X-Cache-Status $upstream_cache_status;
    }
    location /article {
        proxy_cache STATIC;
        proxy_pass http://nextjs_upstream;
        # For testing cache - remove before deploying to production
        # add_header X-Cache-Status $upstream_cache_status;
    }
    location /favicon.ico {
         root /home/pravosleva/pravosleva-blog/frontend/public;
    }
    location / {
        if ($request_method = 'POST') {
           add_header 'Access-Control-Allow-Origin' '*';
           add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
           add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
           add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
        }
        if ($request_method = 'GET') {
           add_header 'Access-Control-Allow-Origin' '*';
           add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
           add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
           add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
        }
        # proxy_pass          http://127.0.0.1:9000;
        proxy_pass http://nextjs_upstream;
        proxy_http_version  1.1;
    }

    # Special for images (which placed in backend/uploads):

    location /api/uploads {
        rewrite ^/api/(.*)$ /$1 break;
        root /home/pravosleva/pravosleva-blog/backend/public;
        # So, files by /api/uploads fill be searched in (root) ~/uploads 
        # See also: https://stackoverflow.com/questions/18954827/how-to-serve-images-with-nginx
    }

    # All /api rqs should be redirected to Strapi powered backend:

    location /api {
        rewrite ^/api/(.*)$ /$1 break;
        proxy_pass          http://127.0.0.1:1337;
    }

    # Others API rqs:

    location /admin {
        proxy_pass          http://127.0.0.1:1337;
    }
    location /users-permissions {
        proxy_pass          http://127.0.0.1:1337;
    }
    location /content-manager {
        proxy_pass          http://127.0.0.1:1337;
    }
    location /upload {
        proxy_pass          http://127.0.0.1:1337;
    }
}

Platform

nodejs@12.14.0. How to install.

Process manager

And also pm2@4.2.1 used as process manager (installed by npm globally).