<?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: Remy Gardette</title>
    <description>The latest articles on DEV Community by Remy Gardette (@remyg).</description>
    <link>https://dev.to/remyg</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%2F23640%2Fc4b2679a-b54f-42c8-ab82-2b19d299d193.jpg</url>
      <title>DEV Community: Remy Gardette</title>
      <link>https://dev.to/remyg</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/remyg"/>
    <language>en</language>
    <item>
      <title>Using multiple SSH keys concurrently</title>
      <dc:creator>Remy Gardette</dc:creator>
      <pubDate>Mon, 10 Jul 2023 14:05:13 +0000</pubDate>
      <link>https://dev.to/remyg/using-multiple-ssh-keys-concurrently-mn3</link>
      <guid>https://dev.to/remyg/using-multiple-ssh-keys-concurrently-mn3</guid>
      <description>&lt;p&gt;When using multiple GitLab accounts (e.g. private account and work account) on the same computer, you can't use the same SSH key for both. This can become problematic when Git has to decide which key to use to communicate with the distant repository.&lt;/p&gt;

&lt;p&gt;There are 2 main solutions to this problem. You can specify the SSH key to use:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;based on the distant repository host,&lt;/li&gt;
&lt;li&gt;or based on the project path.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The following examples assume that you have the 2 SSH keys &lt;code&gt;~/.ssh/id_rsa_perso&lt;/code&gt; and &lt;code&gt;~/.ssh/id_rsa_work&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Host-based configuration
&lt;/h2&gt;

&lt;p&gt;The first solution requires you to change the URL of the repository when cloning it.&lt;/p&gt;

&lt;p&gt;For example, when cloning a work project located at &lt;code&gt;https://gitlab.com/my-org/my-project&lt;/code&gt;, the command would be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git clone git@work-gitlab.com:my-org/my-project.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and for a personal project located at &lt;code&gt;https://gitlab.com/me/my-project&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;git clone git@home-gitlab.com:me/my-project.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, in the SSH configuration file (&lt;code&gt;~/.ssh/config&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;# Personal account:
Host home-gitlab.com
  HostName gitlab.com
  User git
  IdentityFile ~/.ssh/id_rsa_perso
  PreferredAuthentications publickey
  PasswordAuthentication no
  IdentitiesOnly yes

# Work account:
Host work-gitlab.com
  HostName gitlab.com
  User git
  IdentityFile ~/.ssh/id_rsa_work
  PreferredAuthentications publickey
  PasswordAuthentication no
  IdentitiesOnly yes
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This works fine, but it requires you to always remember to modify the project URL when cloning it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Path-based configuration
&lt;/h2&gt;

&lt;p&gt;Since Git 2.13, a conditional include is available in the local Git configuration. This means that you can include a specific configuration file when your current path matches a specific filter.&lt;/p&gt;

&lt;p&gt;For example, if your work projects are located in &lt;code&gt;~/work/sources&lt;/code&gt; and your personal project in &lt;code&gt;~/perso/sources&lt;/code&gt;, you can create a Git work-related configuration file &lt;code&gt;~/.gitconfig-work&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;[user]
    email = "your.email@work.com"
[core]
    sshCommand = "ssh -i ~/.ssh/id_rsa_work"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and a personal configuration file &lt;code&gt;~/.gitconfig-perso&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;[user]
    email = "your.email@home.com"
[core]
    sshCommand = "ssh -i ~/.ssh/id_rsa_perso"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you only need to include the correct configuration file based on your path, by modifying the global &lt;code&gt;~/.gitconfig&lt;/code&gt; file and including:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[includeIf "gitdir:~/work/sources/"]
    path = .gitconfig-work
[includeIf "gitdir:~/perso/sources/"]
    path = .gitconfig-perso
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;I personally find the path-based solution much easier to use, since you only need to change your configuration once, and it automatically works in the future (as long as you use the correct folders for your projects). The host-based solution requires you to always be careful to change the URL when cloning a repository. But it can be useful if you don't want to group your projects in specific local directories.&lt;/p&gt;

&lt;p&gt;Originally published at &lt;a href="https://remyg.fr/blog/2022/11/17/using-multiple-ssh-keys-concurrently/"&gt;https://remyg.fr&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>ssh</category>
      <category>git</category>
    </item>
    <item>
      <title>Deploying Jekyll with GitLabCI</title>
      <dc:creator>Remy Gardette</dc:creator>
      <pubDate>Wed, 27 Feb 2019 10:00:00 +0000</pubDate>
      <link>https://dev.to/remyg/deploying-jekyll-with-gitlabci-1ggj</link>
      <guid>https://dev.to/remyg/deploying-jekyll-with-gitlabci-1ggj</guid>
      <description>&lt;p&gt;&lt;em&gt;This post was first published &lt;a href="https://remyg.fr/blog/2019/02/27/deploying-jekyll-with-gitlabci/"&gt;on my blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;My blog is based on &lt;a href="https://jekyllrb.com/"&gt;Jekyll&lt;/a&gt;, a static website generator. This means that the pages need to be generated before they’re deployed. Until recently, I used to build the content locally using a &lt;a href="https://hub.docker.com/r/jekyll/jekyll"&gt;Jekyll Docker image&lt;/a&gt;, commit and push the generated content to my &lt;a href="https://github.com/RemyG/remyg.ovh"&gt;GitHub repo&lt;/a&gt;, SSH to my web server, and pull the changes from the repo.&lt;/p&gt;

&lt;p&gt;The process was quite annoying, which is why I decided to set up a CI/CD (Continuous Integration and Delivery) pipeline, using &lt;a href="https://docs.gitlab.com/ee/ci/"&gt;GitLabCI&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pipeline
&lt;/h2&gt;

&lt;p&gt;The CI/CD pipeline I’ve implemented is the following:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ngEu10sA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://remyg.fr/assets/img/jekyll-gitlab-ci.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ngEu10sA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://remyg.fr/assets/img/jekyll-gitlab-ci.png" alt="GitLabCI Pipeline"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The pipeline is defined in a file &lt;code&gt;.gitlab-ci.yml&lt;/code&gt; at the root of the project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;image: ruby:2.5

cache:
  key: "jekyll"
  paths:
    - vendor

variables:
  JEKYLL_ENV: production
  LC_ALL: C.UTF-8
  NOKOGIRI_USE_SYSTEM_LIBRARIES: "true"

before_script:
- bundle install

test:
  stage: test
  script:
  - bundle exec jekyll build -d ./public
  - bundle exec htmlproofer ./public --only-4xx --check-favicon --check-html --assume-extension
  artifacts:
    paths:
    - public

deploy:
  stage: deploy
  before_script:
  - 'which ssh-agent || ( apt-get update -y &amp;amp;&amp;amp; apt-get install openssh-client -y )'
  - eval $(ssh-agent -s)
  - ssh-add &amp;lt;(echo "$SSH_PRIVATE_KEY" | base64 -d)
  - mkdir -p ~/.ssh
  - chmod 700 ~/.ssh
  - echo "$SSH_HOST_KEY" &amp;gt; ~/.ssh/known_hosts
  - chmod 644 ~/.ssh/known_hosts
  - which rsync || ( apt-get update -y &amp;amp;&amp;amp; apt-get install rsync -y )
  script:
  - ssh -p$SSH_PORT $SSH_SRV "mkdir -p /tmp/jekyll"
  - ssh -p$SSH_PORT $SSH_SRV "rm -rf /tmp/jekyll_old"
  - ssh -p$SSH_PORT $SSH_SRV "mv /tmp/jekyll /tmp/jekyll_old"
  - rsync -rav -e "ssh -p $SSH_PORT" --exclude='.git/' --exclude='.gitlab-ci.yml' --delete-excluded ./public $SSH_SRV:/tmp/jekyll
  - ssh -p$SSH_PORT $SSH_SRV "sh /home/gitlabci/rsync-jekyll.sh"
  only:
  - master

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;It consists of 2 steps: &lt;code&gt;test&lt;/code&gt; and &lt;code&gt;deploy&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;test&lt;/code&gt; step builds the Jekyll project, then runs &lt;a href="https://github.com/gjtorikian/html-proofer"&gt;HTMLProofer&lt;/a&gt; on the generated files. This step will check and validate the HTML output.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;deploy&lt;/code&gt; step transfers the generated files to my home gateway, then runs a script (located on the gateway) to transfer those files to my web server (the web server is not exposed outside of my network).&lt;/p&gt;

&lt;h2&gt;
  
  
  SSH Configuration
&lt;/h2&gt;

&lt;p&gt;The gateway is accessed via SSH. To do that, I’ve created a specific SSH key only used by GitLab CI.&lt;/p&gt;

&lt;p&gt;To generate a new SSH key:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ssh-keygen -o -t rsa -b 4096 -C "gitlabci"

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The public key needs to be added to the authorized keys before it can be used:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cat ~/.ssh/id_rsa.pub &amp;gt;&amp;gt; ~/.ssh/authorized_keys

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Configuration
&lt;/h2&gt;

&lt;p&gt;The pipeline contains variables to improve the security:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;SSH_PRIVATE_KEY&lt;/code&gt;: a base-64 representation of the SSH private key used to access my gateway. The value is retrieved by running this command on the gateway:
&lt;code&gt;cat id_rsa &amp;gt; base64 -w0&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;SSH_HOST_KEY&lt;/code&gt;: the RSA key of the gateway. Retrieved by running on the gateway:
&lt;code&gt;ssh-keyscan -t rsa server_ip&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;SSH_SRV&lt;/code&gt;: the SSH connection information, like &lt;code&gt;my_user@my_server&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;SSH_PORT&lt;/code&gt;: the SSH port on the gateway&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Usage
&lt;/h2&gt;

&lt;p&gt;I can now follow the following process to publish changes to my website:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;if needed, clone the GitHub repo on my computer&lt;/li&gt;
&lt;li&gt;make the changes (create a new blog post,…)&lt;/li&gt;
&lt;li&gt;test the changes locally (the Docker compose file allows me to build and serve the website on my computer)&lt;/li&gt;
&lt;li&gt;commit and push the changes

&lt;ul&gt;
&lt;li&gt;if I push to a branch other than &lt;code&gt;master&lt;/code&gt;, only the &lt;code&gt;test&lt;/code&gt; step is executed&lt;/li&gt;
&lt;li&gt;if I push to &lt;code&gt;master&lt;/code&gt;, the whole pipeline is executed, so my site is built, tested and automatically deployed.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>jekyll</category>
      <category>gitlabci</category>
    </item>
    <item>
      <title>NGINX Reverse Proxy</title>
      <dc:creator>Remy Gardette</dc:creator>
      <pubDate>Sun, 29 Jul 2018 10:00:00 +0000</pubDate>
      <link>https://dev.to/remyg/nginx-reverse-proxy-54d7</link>
      <guid>https://dev.to/remyg/nginx-reverse-proxy-54d7</guid>
      <description>&lt;p&gt;My home server setup is composed of several Raspberry Pi, where I host different web applications (this blog, an RSS reader, some home IOT apps…). I’ve decided to setup a front gateway, that proxies the request to the right server:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fremyg.ovh%2Fassets%2Fimg%2Freverse-proxy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fremyg.ovh%2Fassets%2Fimg%2Freverse-proxy.png" alt="Infrastructure"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The requests are proxied by an NGINX reverse proxy, running in a Docker container on the gateway. It redirects the HTTP requests based on the host (eg. &lt;code&gt;remyg.ovh&lt;/code&gt; runs on &lt;code&gt;rpi1&lt;/code&gt; when &lt;code&gt;rss.remyg.ovh&lt;/code&gt; runs on rpi2).&lt;/p&gt;

&lt;h2&gt;
  
  
  NGINX Configuration
&lt;/h2&gt;

&lt;p&gt;The main NGINX conf file (&lt;code&gt;nginx.conf&lt;/code&gt;) looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;user nginx;
worker_processes 1;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;

events {
    worker_connections 1024;
}

http {
    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    log_format main '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log /var/log/nginx/access.log main;

    sendfile on;
    #tcp_nopush on;

    keepalive_timeout 65;

    #gzip on;

    include /etc/nginx/sites-enabled/*.*;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The only difference with the base conf file (from the default NGINX Docker image) is the last line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;include /etc/nginx/conf.d/*.conf;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;is replaced by&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;include /etc/nginx/sites-enabled/*.*;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It ignores the default configuration (&lt;code&gt;/etc/nginx/conf.d/default.conf&lt;/code&gt;) and uses the proxy configuration files that I defined.&lt;/p&gt;

&lt;h2&gt;
  
  
  Hosts Configuration
&lt;/h2&gt;

&lt;p&gt;Each host has its own configuration file:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;for &lt;strong&gt;remyg.ovh&lt;/strong&gt; , running on rpi1 (with a local IP 192.168.0.10, and port 8080):
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;server {
    listen 80;
    server_name remyg.ovh;
    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;
    location / {
        proxy_pass http://192.168.0.10:8080;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_redirect off;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;for &lt;strong&gt;rss.remyg.ovh&lt;/strong&gt; , running on rpi2 (with a local IP 192.168.0.11, and port 8081):
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;server {
    listen 80;
    server_name rss.remyg.ovh;
    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;
    location / {
        proxy_pass http://192.168.0.11:8081;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_redirect off;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These files indicate that a request incoming to rss.remyg.ovh:80 (&lt;code&gt;server_name&lt;/code&gt; and &lt;code&gt;listen&lt;/code&gt;) will be redirected to 192.168.0.11:8081 (&lt;code&gt;proxy_pass&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;That’s all the configuration you need to serve websites on HTTP.&lt;/p&gt;

&lt;h2&gt;
  
  
  Running in Container
&lt;/h2&gt;

&lt;p&gt;To run the reverse proxy in a Docker container, the file tree looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nginx-reverse-proxy
  -&amp;gt; conf
    -&amp;gt; nginx.conf
  -&amp;gt; sites
    -&amp;gt; remyg.ovh
       rss.remyg.ovh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With this structure, the command launching the container will be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker run --name mynginx-proxy \
-v /home/pi/nginx-reverse-proxy/sites:/etc/nginx/sites-enabled:ro \
-v /home/pi/nginx-reverse-proxy/conf/nginx.conf:/etc/nginx/nginx.conf:ro \
-p 80:80 -d nginx:alpine
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  HTTPS
&lt;/h2&gt;

&lt;p&gt;To enable HTTPS on the different sites, I’m using Let’s Encrypt, and their utility app Certbot.&lt;/p&gt;

&lt;p&gt;I’m starting by installing the &lt;code&gt;certbot&lt;/code&gt; package:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt install certbot
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When generating a certificate, Certbot will need to validate that it can access a specific file that it generates, pointing to the URL &lt;code&gt;http://your-host/.well-known/acme-challenge/{token}&lt;/code&gt;. To do that, start by creating and mounting a new volume on the reverse proxy container:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker run --name mynginx-proxy \
        -v /home/pi/nginx-reverse-proxy/sites:/etc/nginx/sites-enabled:ro \
        -v /home/pi/nginx-reverse-proxy/conf/nginx.conf:/etc/nginx/nginx.conf:ro \
        -v /home/pi/letsencrypt_www:/var/www/letsencrypt \
        -p 80:80 -p 443:443 -d nginx:alpine
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then specify in the sites proxy configuration that this volume is used when pointing to &lt;code&gt;/.well-known/acme-challenge/&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;server {
    listen 80;
    server_name remyg.ovh;
    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    location /.well-known/acme-challenge/ {
        root /var/www/letsencrypt;
    }

    location / {
        proxy_pass http://192.168.0.10:8080;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_redirect off;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And reload your NGINX config:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker exec -it mynginx-proxy nginx -s reload
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you can generate the certificate(s) :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo certbot certonly --authenticator webroot -w /home/pi/letsencrypt_www -d remyg.ovh -d rss.remyg.ovh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will generate the ACME challenge files in &lt;code&gt;/home/pi/letsencrypt_www&lt;/code&gt;, and validate the challenge. It will also generate the certificates, in &lt;code&gt;/etc/letsencrypt/certs/live/remyg.ovh/&lt;/code&gt; and &lt;code&gt;/etc/letsencrypt/certs/live/rss.remyg.ovh/&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The last step is to use the new certificates, and only allow HTTPS requests.&lt;/p&gt;

&lt;p&gt;Start by mounting a new volume, containing the certificates:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker run --name mynginx-proxy \
        -v /home/pi/nginx-reverse-proxy/sites:/etc/nginx/sites-enabled:ro \
        -v /home/pi/nginx-reverse-proxy/conf/nginx.conf:/etc/nginx/nginx.conf:ro \
        -v /etc/letsencrypt:/etc/nginx/certs \
        -v /home/pi/letsencrypt_www:/var/www/letsencrypt \
        -p 80:80 -p 443:443 -d nginx:alpine
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then update your proxy configuration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;server {
    listen 80;
    server_name remyg.ovh;
    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    location /.well-known/acme-challenge/ {
        root /var/www/letsencrypt;
    }

    location / {
        return 301 https://$host$request_uri;
    }
}

server {
    listen 443 ssl;
    server_name remyg.ovh;

    ssl_certificate certs/live/remyg.ovh/fullchain.pem;
    ssl_certificate_key certs/live/remyg.ovh/privkey.pem;

    location / {
        proxy_pass http://192.168.0.10:8080;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_redirect off;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Reload the NGINX configuration, and you’re all set!&lt;/p&gt;

</description>
      <category>docker</category>
      <category>nginx</category>
      <category>raspberrypi</category>
      <category>cerbot</category>
    </item>
    <item>
      <title>Hi, I'm Remy Gardette</title>
      <dc:creator>Remy Gardette</dc:creator>
      <pubDate>Fri, 30 Jun 2017 21:29:23 +0000</pubDate>
      <link>https://dev.to/remyg/hi-im-remy-gardette</link>
      <guid>https://dev.to/remyg/hi-im-remy-gardette</guid>
      <description>&lt;p&gt;I have been coding for 8 years.&lt;/p&gt;

&lt;p&gt;You can find me on GitHub as &lt;a href="https://github.com/RemyG" rel="noopener noreferrer"&gt;RemyG&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I live in Lille, France.&lt;/p&gt;

&lt;p&gt;I work for IBM Client Innovation Center.&lt;/p&gt;

&lt;p&gt;I mostly program in these languages: Java / JEE.&lt;/p&gt;

&lt;p&gt;Nice to meet you.&lt;/p&gt;

</description>
      <category>introduction</category>
    </item>
  </channel>
</rss>
