<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Quentin de Quelen</title>
    <description>The latest articles on DEV Community by Quentin de Quelen (@qdequele).</description>
    <link>https://dev.to/qdequele</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F326401%2F06598358-2114-447e-83af-c08af511e6ba.jpeg</url>
      <title>DEV Community: Quentin de Quelen</title>
      <link>https://dev.to/qdequele</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/qdequele"/>
    <language>en</language>
    <item>
      <title>How to use HTTP/2 and SSL with MeiliSearch</title>
      <dc:creator>Quentin de Quelen</dc:creator>
      <pubDate>Thu, 24 Sep 2020 12:06:11 +0000</pubDate>
      <link>https://dev.to/meilisearch/how-to-use-http-2-and-ssl-with-meilisearch-h4p</link>
      <guid>https://dev.to/meilisearch/how-to-use-http-2-and-ssl-with-meilisearch-h4p</guid>
      <description>&lt;p&gt;For those willing to use HTTP/2, please be aware that it is &lt;strong&gt;only possible if your server is configured with SSL certificate&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Therefore, you will see how to launch a MeiliSearch server with SSL. This tutorial gives a short introduction to do it locally, but you can as well do the same thing on a remote server.&lt;/p&gt;

&lt;p&gt;First of all, you need the &lt;a href="https://docs.meilisearch.com/reference/features/installation.html"&gt;binary of MeiliSearch&lt;/a&gt;, or you can also use docker. In the latter case, it is necessary to pass the parameters using environment variables and the SSL certificates via a volume.&lt;/p&gt;

&lt;p&gt;A tool to generate SSL certificates is also required. In this How To, you will use &lt;a href="https://github.com/FiloSottile/mkcert"&gt;mkcert&lt;/a&gt;. However, if on a remote server, you can also use certbot or certificates signed by a Certificate Authority.&lt;/p&gt;

&lt;p&gt;Then, use &lt;code&gt;curl&lt;/code&gt; to do requests. It is a simple way to specify that you want to send HTTP/2 requests by using the &lt;code&gt;--http2&lt;/code&gt; option.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try to use HTTP/2 without SSL
&lt;/h2&gt;

&lt;p&gt;Start by running the binary.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;./meilisearch
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And then, send a request.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -kvs --http2 --request GET 'http://localhost:7700/indexes'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will get the following answer from the server:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;*   Trying ::1...
* TCP_NODELAY set
* Connection failed
* connect to ::1 port 7700 failed: Connection refused
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 7700 (#0)
&amp;gt; GET /indexes HTTP/1.1
&amp;gt; Host: localhost:7700
&amp;gt; User-Agent: curl/7.64.1
&amp;gt; Accept: */*
&amp;gt; Connection: Upgrade, HTTP2-Settings
&amp;gt; Upgrade: h2c
&amp;gt; HTTP2-Settings: AAMAAABkAARAAAAAAAIAAAAA
&amp;gt;
&amp;lt; HTTP/1.1 200 OK
&amp;lt; content-length: 2
&amp;lt; content-type: application/json
&amp;lt; date: Fri, 17 Jul 2020 11:01:02 GMT
&amp;lt;
* Connection #0 to host localhost left intact
[]* Closing connection 0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can see on line &lt;code&gt;&amp;gt; Connection: Upgrade, HTTP2-Settings&lt;/code&gt; that the server tries to upgrade to HTTP/2, but is unsuccessful.&lt;br&gt;
The answer &lt;code&gt;&amp;lt; HTTP/1.1 200 OK&lt;/code&gt; indicates that the server still uses HTTP/1.&lt;/p&gt;
&lt;h2&gt;
  
  
  Try to use HTTP/2 with SSL
&lt;/h2&gt;

&lt;p&gt;This time, start by generating the SSL certificates. mkcert creates two files: &lt;code&gt;127.0.0.1.pem&lt;/code&gt; and &lt;code&gt;127.0.0.1-key.pem&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkcert '127.0.0.1'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, use the certificate and the key to configure MeiliSearch with SSL.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;./meilisearch --ssl-cert-path ./127.0.0.1.pem --ssl-key-path ./127.0.0.1-key.pem
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, make the same request as above but change &lt;code&gt;http://&lt;/code&gt; to &lt;code&gt;https://&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -kvs --http2 --request GET 'https://localhost:7700/indexes'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will get the following answer from the server:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;*   Trying ::1...
* TCP_NODELAY set
* Connection failed
* connect to ::1 port 7700 failed: Connection refused
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 7700 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/cert.pem
  CApath: none
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS change cipher, Change cipher spec (1):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* ALPN, server accepted to use h2
* Server certificate:
*  subject: O=mkcert development certificate; OU=quentindequelen@s-iMac (Quentin de Quelen)
*  start date: Jun  1 00:00:00 2019 GMT
*  expire date: Jul 17 10:38:53 2030 GMT
*  issuer: O=mkcert development CA; OU=quentindequelen@s-iMac (Quentin de Quelen); CN=mkcert quentindequelen@s-iMac (Quentin de Quelen)
*  SSL certificate verify result: unable to get local issuer certificate (20), continuing anyway.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x7ff601009200)
&amp;gt; GET /indexes HTTP/2
&amp;gt; Host: localhost:7700
&amp;gt; User-Agent: curl/7.64.1
&amp;gt; Accept: */*
&amp;gt;
* Connection state changed (MAX_CONCURRENT_STREAMS == 4294967295)!
&amp;lt; HTTP/2 200
&amp;lt; content-length: 2
&amp;lt; content-type: application/json
&amp;lt; date: Fri, 17 Jul 2020 11:06:27 GMT
&amp;lt;
* Connection #0 to host localhost left intact
[]* Closing connection 0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can see that the server now supports HTTP/2.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The server successfully receives HTTP/2 requests.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt; HTTP/2 200
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>meilisearch</category>
      <category>certbot</category>
      <category>ssl</category>
      <category>mkcert</category>
    </item>
  </channel>
</rss>
