• Docs >
  • 9. Magento in Apache or Nginx backend + ShimmerCat
Shortcuts

9. Magento in Apache or Nginx backend + ShimmerCat

Magento + ShimmerCat

  • Do you own an online store deployed with Apache or Nginx serving your backend?

  • Would like to have significant loading time improvements on your website or deliver faster websites to your clients?

If you answer “Yes” to most of the questions above, then you have come to the right place. This tutorial is for you!

9.1. Prerequisites

We will assume that you have either:

In any of those cases you should already have created:

You should also have your Magento store deployed somewhere with Apache or Nginx, and deploy edges servers using HTTP as fetch backend as well. Note that you don’t need to change anything on your backend to test the tutorial. If you need help with a different deployment process don’t hesitate to contact us at ops@shimmercat.com or through our ticket system.

We are sharing most of the configuration we have done on the demo to guide you with a practical example. This specific example uses a Magento backend, but you could have your backend developed using any other framework, of course. See below.

9.2. About haproxy config

Basically the haproxy config file should contain the following:

global
    log /dev/log     local0
    log /dev/log     local1 notice
    user shimmercat
    group shimmercat

listen stats
    bind :9000
    mode http
    stats enable
    stats realm Haproxy\ Statistics
    stats uri /haproxy_stats
    stats auth shimmercat:4.15.0-32-generic

frontend http_to_https_redirects
    bind *:80
    timeout client 20s
    mode http

    # ShimmerCat can do HTTP to HTTPS redirects, and so can Haproxy
    redirect scheme https code 301

frontend https
    bind *:443
    timeout client 3m
    option tcplog
    log /dev/log local0

    # ShimmerCat will do TLS termination, and fingerprinting, thus it is
    # important to keep the proxy mode as TCP.
    mode tcp

    tcp-request inspect-delay 5s
    tcp-request content accept if { req_ssl_hello_type 1 }
    default_backend shimmercat_deployments

backend shimmercat_deployments
    # HTTPS will be terminated by ShimmerCat, this enumerates the
    # two ShimmerCat instances running in this very edge server
    timeout server 3m
    timeout connect 5s
    server deployment_A 127.0.0.1:4030 check port 8030 send-proxy-v2

frontend to_application
    bind *:4430
    timeout client 3m
    timeout server 3m
    timeout connect 5s

    mode http
    default_backend example_application_servers

backend example_application_servers
    mode http
    timeout server 10s
    timeout connect 10s
    timeout check 10s

    server server_001 www.example.com:443 check port www.example:443 ssl verify none sni str("www.example.com")

Notes:

  1. The scheme that we have followed in this configuration is the following: Haproxy port 443 -> ShimmerCat 4030 -> Haproxy 4430 -> Origin server Haproxy captures the request through port 443 and asks ShimmerCat to process it by the 4030, then ShimmerCat calls haproxy by the port 4430 and this is responsible for calling the web application.

9.3. The devlove.yaml file

In the devlove.yaml at the install-dir of your sc_pack, fill-in content similar to the one below, taking care of changing the connect-to and the domain names after elec with values that match your desired configuration:

---
shimmercat-devlove:
  domains:
    elec www.example.com:
      root-dir:
        use-consultant: default
      views-dir: views-dir
      consultants:
        default:
          connect-to: "127.0.0.1:4430"
          application-protocol: http
          encryption-level: plain
      bot-protection-enabled: false
      change-url:
        - //+</\.(js|css|jpg|png|gif|bmp|txt|svg|woff2|woff|ttf|json)/> -> <*>
        - / -> /target/+common/
        - //+/ -> /target/+common/slash/<+>
        - //+ -> /target/+common/no-slash/<+>/

To know more about the fetch backends ShimmerCat supports take a look here.

9.4. A set of views for Magento

Create all the directories and files listed below under the sc_pack’s install-dir directory, and devlove.yaml’s views-dir directory. For instance, if your sc_pack installation directory is /srv/deployment_A and the devlove.yaml contains views-dir: views-dir, then the first view listed below should be at /srv/deployment_A/views-dir/target/+common/index.html.

  • views-dir/target/+common/index.html

<!--
shimmercat:
    change-url:
       - /target/+common/ -> /
    content-disposition: replace
-->
  • views-dir/target/+common/__index.html

<!--
shimmercat:
    change-url:
       - /target/+common//+/ -> /
    content-disposition: replace
-->
  • views-dir/target/+common/no-slash/__index.html

<!--
shimmercat:
  content-disposition: replace
  change-url:
     - /target/+common/no-slash//+/ -> /<+>
-->
  • views-dir/target/+common/slash/__index.html

<!--
shimmercat:
  content-disposition: replace
  change-url:
     - /target/+common/slash//+/ -> /<+>
-->

If you want to know more about the rules and views we wrote above, please read: URL handling and re-writes and Views and devlove.

To run the service, you can use the command:

$ sc_pack ctl reload shimmercat

You can also start it at boot time.

As usual when testing a website locally:

  • modify your /etc/hosts to have that line: 127.0.0.1 www.example.com

  • open a browser and visit: https://www.example.com:4043/, that port depends on what you set on the sc_pack.conf.yaml of course.

Again don’t hesitate to contact us at ops@shimmercat.com or through our ticket system if you need our help with that.

Thanks a lot for your time, and keep reading!