X
    Categories Tutorials

Set up Magento 2 with Redis, Varnish and Nginx as SSL termination

In this article, we will show you how to install Magento 2 on an Ubuntu 16.04 VPS with MariaDB, PHP-FPM 7.0, Varnish as a full page cache, Nginx as SSL termination and Redis for session storage and page caching.  This guide should work on other Linux VPS systems as well but was tested and written for an Ubuntu 16.04 VPS.

Login to your VPS via SSH

ssh my_sudo_user@my_server

Update the system and install necessary packages

sudo apt-get update && sudo apt-get -y upgrade
sudo apt-get -y install curl nano git

Install MariaDB 10.0

Install the latest MariaDB 10.0 server from the official Ubuntu repositories:

sudo apt-get install -y mariadb-server

When the installation is complete, run the following command to secure your installation:

mysql_secure_installation

Next, we need to create a database for our Magento installation.

mysql -uroot -p
MariaDB [(none)]> CREATE DATABASE magento;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON magento.* TO 'magento'@'localhost' IDENTIFIED BY 'my_strong_password';
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> \q

Install PHP 7.0, composer and all required PHP modules

To install the latest stable version of PHP 7.0 and all necessary modules, run:

sudo apt-get -y install php-fpm php-cli php-gd php-imagick php-mysql php-mcrypt php-pear php-curl php-intl php-xsl php-zip php-mbstring

Change few default PHP settings:

sudo sed -i "s/memory_limit = .*/memory_limit = 256M/" /etc/php/7.0/fpm/php.ini
sudo sed -i "s/upload_max_filesize = .*/upload_max_filesize = 128M/" /etc/php/7.0/fpm/php.ini
sudo sed -i "s/zlib.output_compression = .*/zlib.output_compression = on/" /etc/php/7.0/fpm/php.ini
sudo sed -i "s/max_execution_time = .*/max_execution_time = 18000/" /etc/php/7.0/fpm/php.ini

Composer is a dependency manager for PHP with which you can install packages. Composer will pull in all the required libraries and dependencies you need for your project.

curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer

Install Magento 2 from Github

Clone the Magento repository to the ~/myMagentoSite.com directory using the following command:

sudo git clone https://github.com/magento/magento2.git /var/www/myMagentoSite.com

Get the latest stable release, at the time of the writing it’s Magento 2.1.2:

cd /var/www/myMagentoSite.com
sudo git checkout $(git describe --tags $(git rev-list --tags --max-count=1))

Run composer to install all Magento dependencies:

sudo composer install

To continue with the installation you can either use the installation wizard or the command line, in this guide we will use the latter.

sudo bin/magento setup:install \
--base-url=http://myMagentoSite.com/ \
--db-host=localhost \
--db-name=magento \
--db-user=magento \
--db-password=my_strong_password \
--admin-firstname=First  \
--admin-lastname=Last \
--admin-email=user@myMagentoSite.com \
--admin-user=admin \
--admin-password=my_strong_password123 \
--language=en_US \
--currency=USD \
--timezone=America/Chicago \
--use-rewrites=1

If the installation is successful you will see something like below:

[SUCCESS]: Magento installation complete.
[SUCCESS]: Magento Admin URI: /admin_mejj1n

Run the crontab command to create a cronjob

crontab -u www-data -e

and add the following line:

* * * * * /usr/bin/php /var/www/myMagentoSite.com/bin/magento cron:run | grep -v "Ran jobs by schedule" >> /var/www/myMagentoSite.com/var/log/magento.cron.log

Finally, set the correct permissions:

sudo chown -R www-data: /var/www/myMagentoSite.com

Install and configure Nginx

Install Nginx from the official Ubuntu repositories::

sudo apt-get -y install nginx

Create a new Nginx server block with the following content:

sudo nano /etc/nginx/sites-available/myMagentoSite.com
upstream fastcgi_backend {
  server   unix:/run/php/php7.0-fpm.sock;
}

server {
    server_name myMagentoSite.com www.myMagentoSite.com;
    listen 80;
    set $MAGE_ROOT /var/www/myMagentoSite.com;
    set $MAGE_MODE developer; # or production

    access_log /var/log/nginx/myMagentoSite.com-access.log;
    error_log /var/log/nginx/myMagentoSite.com-error.log;

    include /var/www/myMagentoSite.com/nginx.conf.sample;        
}

Activate the server block by creating a symbolic link :

sudo ln -s /etc/nginx/sites-available/myMagentoSite.com /etc/nginx/sites-enabled/myMagentoSite.com

Delete the default configuration:

sudo rm -f /etc/nginx/sites-enabled/default

Test the Nginx configuration and restart nginx:

sudo nginx -t
sudo service nginx restart

You should be now able to login to your Magento back-end by going to http://myMagentoSite.com/admin_mejj1n using the information you set when running the bin/magento setup:install .

Install and configure Varnish

Installing Varnish is as simple as running the following command:

sudo apt-get install varnish

From you Magento Admin dashboard click on the STORES link (left sidebar) -> Configuration -> ADVANCED -> System -> Full Page Cache
Unselected Use system value and from the Caching Application list, select Varnish Cache (Recommended), save the configuration, click on the Varnish Configuration link and click on the Export VCL for Varnish 4 button. The varnish.vcl file which we will use will be exported in the /var/www/myMagentoSite.com/var/ directory.

Flush the Magento cache with:

sudo php bin/magento cache:flush

Delete the /etc/varnish/default.vcl and symlink it to the exported varnish configuration.

sudo rm -f /etc/varnish/default.vcl
sudo ln -sf /var/www/myMagentoSite.com/var/varnish.vcl /etc/varnish/default.vcl

To change varnish port from 6081 to 80, we need to edit the systemd service configuration.

Create a new customexec.conf file

sudo mkdir -p /etc/systemd/system/varnish.service.d
sudo nano /etc/systemd/system/varnish.service.d/customexec.conf

paste the following:

[Service]
ExecStart=
ExecStart=/usr/sbin/varnishd -j unix,user=vcache -F -a :80 -T localhost:6082 -f /etc/varnish/default.vcl -S /etc/varnish/secret -s malloc,256m

and reload systemd units

sudo systemctl daemon-reload

Now we need to change Nginx listening port from 80 to 8080 and enable Nginx SSL termination with HTTP2, to do that open the Nginx configuration file and change it as follows:

sudo nano /etc/nginx/sites-available/myMagentoSite.com
upstream fastcgi_backend {
  server   unix:/run/php/php7.0-fpm.sock;
}

server {
    server_name myMagentoSite.com www.myMagentoSite.com;
    listen 8080;
    set $MAGE_ROOT /var/www/myMagentoSite.com;
    set $MAGE_MODE production; # or developer

    access_log /var/log/nginx/myMagentoSite.com-access.log;
    error_log /var/log/nginx/myMagentoSite.com-error.log;

    include /var/www/myMagentoSite.com/nginx.conf.sample;        
}

server {

    listen 443 ssl http2;
    server_name myMagentoSite.com www.myMagentoSite.com;

    ssl_certificate /etc/ssl/certs/ssl-cert-snakeoil.pem; # change with your SSL cert
    ssl_certificate_key /etc/ssl/private/ssl-cert-snakeoil.key; # change with your SSL key
    ssl_protocols              TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers               'AES128+EECDH:AES128+EDH:!aNULL';
    ssl_session_cache    shared:SSL:10m;
    ssl_session_timeout 24h;
    keepalive_timeout 300s;

    location / {
        proxy_pass http://127.0.0.1;
        proxy_set_header Host $http_host;
        proxy_set_header X-Forwarded-Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Ssl-Offloaded "1";
        proxy_set_header      X-Forwarded-Proto https;
        proxy_set_header      X-Forwarded-Port 443;
        #proxy_hide_header X-Varnish;
        #proxy_hide_header Via;
        proxy_set_header X-Forwarded-Proto $scheme;

    }

}

If you don’t already have an SSL certificate, you can purchase a trusted SSL certificate here.

Restart Varnish and Nginx:

sudo systemctl restart nginx
sudo systemctl restart varnish

Change the base url to https and flush the cache

sudo bin/magento setup:store-config:set --base-url="https://myMagentoSite.com"
sudo php bin/magento cache:flush

If everything is setup correctly now you should be able to login to your Magento back-end by going to https://myMagentoSite.com/admin_mejj1n.

Stuck somewhere? Get a VPS from us and we’ll do all of this for you, free of charge!

Install and configure Redis caching

Redis is a key-value in memory data store and we will use it to replace the default Magento 2 Zend_Cache_Backend_File backend cache.  Install Redis by running the following command:

apt-get install php-redis redis-server

To configure your Magento installation to use Redis for session storage open the app/etc/env.php file and change/add the following:

sudo nano /var/www/myMagentoSite.com/app/etc/env.php

change:

  'session' =>
  array (
    'save' => 'files',
  ),

with:

'session' => 
   array (
   'save' => 'redis',
   'redis' => 
      array (
	'host' => '127.0.0.1',
	'port' => '6379',
	'password' => '',
	'timeout' => '2.5',
	'persistent_identifier' => '',
	'database' => '0',
	'compression_threshold' => '2048',
	'compression_library' => 'gzip',
	'log_level' => '1',
	'max_concurrency' => '6',
	'break_after_frontend' => '5',
	'break_after_adminhtml' => '30',
	'first_lifetime' => '600',
	'bot_first_lifetime' => '60',
	'bot_lifetime' => '7200',
	'disable_locking' => '0',
	'min_lifetime' => '60',
	'max_lifetime' => '2592000'
    )
),

and to use Redis for page caching add:

'cache' =>
array(
   'frontend' =>
   array(
      'default' =>
      array(
         'backend' => 'Cm_Cache_Backend_Redis',
         'backend_options' =>
         array(
            'server' => '127.0.0.1',
            'port' => '6379'
            ),
    ),
    'page_cache' =>
    array(
      'backend' => 'Cm_Cache_Backend_Redis',
      'backend_options' =>
       array(
         'server' => '127.0.0.1',
         'port' => '6379',
         'database' => '1',
         'compress_data' => '0'
       )
    )
  )
),

Finally flush the cache again:

sudo php bin/magento cache:flush

Further Optimizations

To further optimize your Magento installation from you Magento admin dashboard:

1. Go to STORES -> Configuration -> CATALOG -> Catalog -> Use Flat Catalog Category, select Yes and click Save Config.
2. Go to STORES -> Configuration -> ADVANCED -> Developer -> JavaScript Settings and set both Merge JavaScript Files and Minify JavaScript Files to Yes and click Save Config..
3. Go to STORES -> Configuration -> ADVANCED -> Developer -> CSS Settings and set both Merge CSS Files and Minify CSS Files to Yes and click Save Config.
4. Consider using a CDN – Content Delivery Network

Do not forget to flush the cache:

sudo php bin/magento cache:flush

That’s it. You have successfully installed Magento 2 with Redis as a session storage and page caching, Varnish as a full page caching and Nginx as SSL termination on your Ubuntu 16.04 VPS. For more information about how to manage your Magento installation, please refer to the official Magento documentation.


Of course, you don’t have to do any of this if you use one of our Magento VPS Hosting services, in which case you can simply ask our expert Linux admins to setup this for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

admin:

View Comments

  • Well done sir!!

    Works like a charm!
    No errors, no bugs! perfect instalation! my magento is flying righ now!

    Thanks a lot!

  • Hi!

    I'm getting "The requested PHP extension ext-soap * is missing from your system. Install or enable PHP's soap extension" - with Ubuntu 16.0.4, after the 'sudo composer install step'.

    I've worked through the guide three times now, even wiping our VPS instance and starting from scratch - same error each time.

    Any suggestions would be most welcome.

    Thanks,

    Steve

  • With this configuration it is not possible to get the real client-ip , so modules as geoip and fraudlabpro dotsn't work properly! they always shows 127.0.0.1 as a client's ip while this ip is using varnish and passing to nginx! Any idea how to solve it?
    Best Regards

    • Hi Kevin,

      You should be able to achieve this by modifying the 'X-Forwarded-For' header set by Varnish.

  • Can you please be more specific? i was trying few times based on suggestions i 've found on internet, bit everytime i was getting 502 bad getway after that! I have read that only the first time the headers passing the real-ip , if we need to get the real ip everytime , then it has some pipe() commands, which i am not sure i can understand what exactly they are doing, but in each try i was getting 502 error. Also i have read that except Varnish in order to get the right logs at nginx with real-ip it needs some extra configuration! So whil ei am not very familiar with it i would appreciate any further help.

    • To preserve the client IP address try adding the following lines in your Varnish configuration:

      sub vcl_recv {
        unset req.http.X-Forwarded-For;
        set req.http.X-Forwarded-For = client.ip;
      }

      Then restart Varnish and watch the log files.

  • I have added it but it doesn't work! i am still getting 127.0.0.1 at Magento backend for all clients! Probably something more must be added to to nginx??

    Best Regards

  • Hi,

    Thank you for your post it's very great.

    I have a problem with my configuration of nginx.
    Nginx doesn't work

    `--# nginx -t
    nginx: [emerg] duplicate location "/" in /etc/nginx/sites-enabled/magento2:36
    nginx: configuration file /etc/nginx/nginx.conf test failed

    See my file of nginx (/etc/nginx/sites-enabled/magento2) :

    upstream fastcgi_backend {
    server unix:/run/php/php7.0-fpm.sock;
    }

    server {
    server_name xxxx;
    listen 8080;
    set $MAGE_ROOT /var/www/myMagentoSite.com;
    set $MAGE_MODE production; # or developer

    access_log /var/log/nginx/myMagentoSite.com-access.log;
    error_log /var/log/nginx/myMagentoSite.com-error.log;

    include /var/www/myMagentoSite.com/nginx.conf.sample;
    }

    server {

    listen 443 ssl http2;
    server_name xxxx;

    ssl_certificate /etc/letsencrypt/live/xxxx/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/xxxx/privkey.pem;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers 'AES128+EECDH:AES128+EDH:!aNULL';
    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout 24h;
    keepalive_timeout 300s;

    location / {
    proxy_pass http://127.0.0.1;
    proxy_set_header Host $http_host;
    proxy_set_header X-Forwarded-Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Ssl-Offloaded "1";
    proxy_set_header X-Forwarded-Proto https;
    proxy_set_header X-Forwarded-Port 443;
    #proxy_hide_header X-Varnish;
    #proxy_hide_header Via;
    proxy_set_header X-Forwarded-Proto $scheme;

    }

    }

    When I remove he part of "upstream fastcgi_backend" and "include /var/www/magento2/nginx.conf.sample" nginx work.
    "duplicate location /" What is it ?

    Thank you for your help

    Regards,

    Clément.

  • i insert this snippet at sub vcl_recv :

    if (req.restarts == 0) {
    if (req.http.x-forwarded-for) {
    set req.http.X-Forwarded-For = req.http.X-Forwarded-For + ", " + client.ip;
    } else {
    set req.http.X-Forwarded-For = client.ip;
    }
    }

    and i have these directives at nginx/sites-available/mydomain.com
    location / {
    proxy_pass http://127.0.0.1;
    proxy_set_header Host $http_host;
    proxy_set_header X-Forwarded-Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Ssl-Offloaded "1";
    proxy_set_header X-Forwarded-Proto https;
    proxy_set_header X-Forwarded-Port 443;
    #proxy_hide_header X-Varnish;
    #proxy_hide_header Via;
    #proxy_set_header X-Forwarded-Proto $scheme;

    }

    and finally this is what i am getting with Varnishlog command :

    * <> 229756
    - Begin req 229755 rxreq
    - Timestamp Start: 1502220624.492312 0.000000 0.000000
    - Timestamp Req: 1502220624.492312 0.000000 0.000000
    - ReqStart 127.0.0.1 56092
    - ReqMethod GET
    - ReqURL /aromatizatori/aerozolnye-aromati.html?p=3&saturation_rating=52
    - ReqProtocol HTTP/1.0
    - ReqHeader Host: mydomain.com
    - ReqHeader X-Forwarded-Host: mydomain.com
    - ReqHeader X-Real-IP: 66.249.76.78
    - ReqHeader X-Forwarded-For: 66.249.76.78
    - ReqHeader Ssl-Offloaded: 1
    - ReqHeader X-Forwarded-Proto: https
    - ReqHeader X-Forwarded-Port: 443
    - ReqHeader Connection: close
    - ReqHeader Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    - ReqHeader From: googlebot(at)googlebot.com
    - ReqHeader User-Agent: Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)
    - ReqHeader Accept-Encoding: gzip,deflate,br
    - ReqUnset X-Forwarded-For: 66.249.76.78
    - ReqHeader X-Forwarded-For: 66.249.76.78, 127.0.0.1
    - VCL_call RECV
    - ReqUnset X-Forwarded-For: 66.249.76.78, 127.0.0.1
    - ReqHeader X-Forwarded-For: 66.249.76.78, 127.0.0.1, 127.0.0.1
    - ReqURL /aromatizatori/aerozolnye-aromati.html?p=3&saturation_rating=52
    - ReqUnset Accept-Encoding: gzip,deflate,br
    - ReqHeader Accept-Encoding: gzip
    - ReqURL /aromatizatori/aerozolnye-aromati.html?p=3&saturation_rating=52
    - ReqURL /aromatizatori/aerozolnye-aromati.html?p=3&saturation_rating=52
    - ReqURL /aromatizatori/aerozolnye-aromati.html?p=3&saturation_rating=52
    - VCL_return hash
    - VCL_call HASH
    - VCL_return lookup
    - VCL_call MISS
    - VCL_return fetch
    - Link bereq 229757 fetch
    - Timestamp Fetch: 1502220624.995656 0.503343 0.503343
    - RespProtocol HTTP/1.1
    - RespStatus 200
    - RespReason OK
    - RespHeader Server: nginx/1.10.3 (Ubuntu)
    - RespHeader Date: Tue, 08 Aug 2017 19:30:24 GMT
    - RespHeader Content-Type: text/html; charset=UTF-8
    - RespHeader X-Magento-Tags: store,cms_block,catalog_category_127,catalog_category,catalog_category_product_127,catalog_product_441,catalog_product,catalog_product_452,catalog_product_457,catalog_product_461,catalog_product_481,catalog_product_499,cms_block_fastest-g
    - RespHeader X-Content-Type-Options: nosniff
    - RespHeader X-XSS-Protection: 1; mode=block
    - RespHeader X-Frame-Options: SAMEORIGIN
    - RespHeader Vary: Accept-Encoding
    - RespHeader Pragma: no-cache
    - RespHeader Expires: -1
    - RespHeader Cache-Control: no-store, no-cache, must-revalidate, max-age=0
    - RespHeader Content-Encoding: gzip
    - RespHeader X-Varnish: 229756
    - RespHeader Age: 0
    - RespHeader Via: 1.1 varnish-v4
    - VCL_call DELIVER
    - RespUnset Age: 0
    - RespUnset X-Magento-Tags: store,cms_block,catalog_category_127,catalog_category,catalog_category_product_127,catalog_product_441,catalog_product,catalog_product_452,catalog_product_457,catalog_product_461,catalog_product_481,catalog_product_499,cms_block_fastest-g
    - RespUnset Server: nginx/1.10.3 (Ubuntu)
    - RespUnset X-Varnish: 229756
    - RespUnset Via: 1.1 varnish-v4
    - VCL_return deliver
    - Timestamp Process: 1502220624.995700 0.503387 0.000044
    - RespHeader Accept-Ranges: bytes
    - RespHeader Content-Length: 30547
    - Debug "RES_MODE 2"
    - RespHeader Connection: close
    - Timestamp Resp: 1502220624.995744 0.503432 0.000044
    - ReqAcct 499 0 499 396 30547 30943
    - End

    And this is what i am getting form Varnishncsa command :

    127.0.0.1 - - [08/Aug/2017:22:34:09 +0300] "GET http://mydomain.com/gretseskaja-konservatsija/tomatnaja-gruppa/tomaty-sushenye-v-masle-monastyrskie-delphi-340g.html HTTP/1.0" 200 26286 "https://mydomain.com/gretseskaja-konservatsija/tomatnaja-gruppa.html" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:54.0) Gecko/20100101 Firefox/54.0"
    127.0.0.1 - - [08/Aug/2017:22:34:10 +0300] "GET http://mydomain.com/static/version1502219420/frontend/mage/calendar.css HTTP/1.0" 304 0 "https://mydomain.com/gretseskaja-konservatsija/tomatnaja-gruppa/tomaty-sushenye-v-masle-monastyrskie-delphi-340g.html" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:54.0) Gecko/20100101 Firefox/54.0"

    In anyway Magento always shows 127.0.0.1 to client's ip at order view!
    What i am missing yet?
    Best Regards

  • And finally the nginx logs are :

    root@mydomain:/var/log/nginx# cat access.log
    81.19.78.134 - - [08/Aug/2017:22:48:57 +0300] "GET /media/email/logo/default/logo_2.png HTTP/1.0" 200 30463 "https://mail.rambler.ru/" "RamblerMail/6.0 (incompatible; ImageProxy/6.0)"
    66.249.76.80 - - [08/Aug/2017:22:49:01 +0300] "GET /gretsesk-olivkovoe-maslo.html?oil_packing_material=34&oliveoil_acidity=-&volume=8 HTTP/1.1" 200 29120 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
    66.249.76.78 - - [08/Aug/2017:22:49:20 +0300] "GET /aromatizatori/aerozolnye-aromati.html?p=5&saturation_rating=53 HTTP/1.1" 200 30671 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
    root@gmydoamin.com:/var/log/nginx# cat mydomain.com-access.log
    127.0.0.1 - - [08/Aug/2017:22:48:57 +0300] "GET /media/email/logo/default/ogo_2.png HTTP/1.1" 200 30463 "https://mail.rambler.ru/" "RamblerMail/6.0 (incompatible; ImageProxy/6.0)"
    127.0.0.1 - - [08/Aug/2017:22:49:01 +0300] "GET /gretsesk-olivkovoe-maslo.html?oil_packing_material=34&oliveoil_acidity=-&volume=8 HTTP/1.1" 200 29110 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
    127.0.0.1 - - [08/Aug/2017:22:49:20 +0300] "GET /aromatizatori/aerozolnye-aromati.html?p=5&saturation_rating=53 HTTP/1.1" 200 30669 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"

    As it seems the general nginx access log shows the real ips but the domains nginx log shows 127.0.0.1 !!!
    Any help would be very valuable!!
    Best Regards

      • this is the nginx build , which is already compiled --with-http_realip_module option!

        nginx/1.10.3 (Ubuntu)
        built with OpenSSL 1.0.2g 1 Mar 2016
        TLS SNI support enabled
        configure arguments: --with-cc-opt='-g -O2 -fPIE -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -fPIE -pie -Wl,-z,relro -Wl,-z,now' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-ipv6 --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_v2_module --with-http_sub_module --with-http_xslt_module --with-stream --with-stream_ssl_module --with-mail --with-mail_ssl_module --with-threads

        and at nginx.conf exists rows :

        http {
        set_real_ip_from 127.0.0.1; #Put the Ip of your varnish/proxy here
        real_ip_header X-Forwarded-For; #Put the Header that your varnish/proxy set
        ......}

        • Remove the lines starting with error_log and access_log from the nginx 8080 server block and add them to the 443 server block.

  • Tutorial is erroneous.

    "An error has happened during application run. See exception log for details."

  • I'm getting the following error, my varnish version is 4.1.1:

    ● varnish.service - Varnish HTTP accelerator
    Loaded: loaded (/lib/systemd/system/varnish.service; enabled; vendor preset: enabled)
    Drop-In: /etc/systemd/system/varnish.service.d
    └─customexec.conf
    Active: failed (Result: exit-code) since Mon 2017-10-09 17:16:13 GST; 3s ago
    Docs: https://www.varnish-cache.org/docs/4.1/
    man:varnishd
    Process: 9058 ExecStart=/usr/sbin/varnishd -a :80 -T localhost:6082 -f /etc/varnish/default.vcl -S /etc/varnish/secret -s malloc,2
    Main PID: 9058 (code=exited, status=2)

    Oct 09 17:16:13 Magento2-LiveTest varnishd[9058]: Message from VCC-compiler:
    Oct 09 17:16:13 Magento2-LiveTest varnishd[9058]: Unknown variable 'req.http.'
    Oct 09 17:16:13 Magento2-LiveTest varnishd[9058]: At: ('/etc/varnish/default.vcl' Line 78 Pos 15)
    Oct 09 17:16:13 Magento2-LiveTest varnishd[9058]: unset req.http.;
    Oct 09 17:16:13 Magento2-LiveTest varnishd[9058]: --------------#########-
    Oct 09 17:16:13 Magento2-LiveTest varnishd[9058]: Running VCC-compiler failed, exited with 2
    Oct 09 17:16:13 Magento2-LiveTest varnishd[9058]: VCL compilation failed
    Oct 09 17:16:13 Magento2-LiveTest systemd[1]: varnish.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
    Oct 09 17:16:13 Magento2-LiveTest systemd[1]: varnish.service: Unit entered failed state.
    Oct 09 17:16:13 Magento2-LiveTest systemd[1]: varnish.service: Failed with result 'exit-code'.