Optimizations for Ubuntu and NGINX

Hey guys,

I’ve developed my first frontity site (hurrah!) and it’s time for deployment. I tried to use vercel but since I exceed their build timeout of 10s for the free plan, I need to use my own VPS for cost reasons.

Therefore I’m serving Frontity via PM2 and NGINX on a Ubuntu 18.04. I believe the framework is rapid once loaded, but the initial load takes too long time in my opinion.

Do you maybe have any tips on how to enable cache for common GET-routes? Most pages contain the same content, only the webshop pages may vary. But these don’t need SSR either way.

The page is accessible through https://stage.rekarnekott.se and the wp-json API through https://admin.rekarnekott.se (they’re both hosted on the same VPS).

Here’s my config for NGINX:

server {

server_name stage.rekarnekott.se www.stage.rekarnekott.se;

location / {
    proxy_pass http://localhost:3000;
    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 ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/stage.rekarnekott.se/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/stage.rekarnekott.se/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

}
server {
if ($host = stage.rekarnekott.se) {
    return 301 https://$host$request_uri;
} # managed by Certbot


listen 80;
listen [::]:80;

server_name stage.rekarnekott.se www.stage.rekarnekott.se;
return 404; # managed by Certbot


}

Thanks in advance!

For server cache, you can use the same approach and plugins that you would use with WordPress.

If you want to use WordPress cache plugins, like Simple Cache or Super Cache, then you have to use our Embedded mode plugin.

Please bear in mind that the Embedded mode still a proof of concept, although we’ve been using it for a couple of months in production in our https://frontity.org site and we haven’t seen any problems so far.

I especially like the Simple Cache plugin for medium/small sites because it’s really fast and simple. This is a great article comparing it to Varnish and Nginx Fast CGI: https://spinupwp.com/wordpress-page-cache-plugins-nginx/. As you can see, it’s pretty fast. I’m planning to do a PR to add support for the REST API as well.

For the REST API cache, we recommend Acato’s REST Cache plugin.

2 Likes

Hey @luisherranz,

Thanks for the fast and detailed reply. I actually have REST API Cache plugin activated already, but will need to look into your Embedded mode plugin a little bit in the weekend to see how this will fit me.

I’ll mark your reply as the solution for now, as there’s no real “solution” just things you can do to provide more performance :slight_smile: But I really appreciate your help, great thanks!

3 Likes

Awesome. Let us know how it goes :slightly_smiling_face:

1 Like

It went really well, big thanks. You can enjoy for yourself at https://rekarnekott.se.

Awesome! Which option did you use?

I took the approach with Embedded mode plugin and Simple cache.

Ok, great. Let us know how it goes.

By the way, we are about to update the PoC with Preview support. I’ll let you know so you can test it out! :slightly_smiling_face: