<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/shiny-server-series-part-3-adding-ssl-encryption/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://www.jasperginn.nl/shiny-server-series-pt3/"> Jasper Ginn's blog</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><em>This guide is part of a series on setting up your own private server running shiny apps. There are many guides with great advice on how to set up an R shiny server and related software. I try to make a comprehensive guide based in part on these resources as well as my own experiences. I always aim to properly attribute information to their respective sources. If you notice an issue, please contact me.</em></p>
<p>Part 1 of this series is available <a target="_blank" rel="nofollow" href="https://www.jasperginn.nl/shiny-server-series-pt1/">here</a><br>
Part 2 of this series is available <a target="_blank" rel="nofollow" href="https://www.jasperginn.nl/shiny-server-series-pt2/">here</a></p>
<p>In part 1 and part 2 of this series, we set up an ubuntu 16.04 server to host shiny applications. Thus far, we configured shiny server to listen on port 3838 (for public apps) and 4949 (for private apps). In this part, we will set up SSL encryption on the server for additional security.</p>
<h2>Resources used for this part</h2>
<p>This guide is largely based on <a target="_blank" rel="nofollow" href="https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-14-04">this</a> tutorial.</p>
<h2>Adding SSL encryption to your server</h2>
<p>We’re going to use <a target="_blank" rel="nofollow" href="https://certbot.eff.org/">certbot</a> and <a target="_blank" rel="nofollow" href="https://letsencrypt.org/">Let’s encrypt</a> to set up the SSL certificate.</p>
<p>Log into your server and switch to the Shiny user:</p>
<figure>
<pre><code data-lang="shell"><span># Log into the server</span>
ssh root@&lt;your-VPS-ip>
<span># Switch to shiny user</span>
su shiny</code></pre>
</figure>
<p>Go to the <code>sbin</code> folder on your server and download certbot-auto:</p>
<figure>
<pre><code data-lang="shell"><span>cd</span> /usr/local/sbin
sudo wget https://dl.eff.org/certbot-auto</code></pre>
</figure>
<p>Make the script executable:</p>
<figure>
<pre><code data-lang="shell">sudo chmod a+x /usr/local/sbin/certbot-auto</code></pre>
</figure>
<p>Now, open up the nginx configuration:</p>
<figure>
<pre><code data-lang="shell">sudo nano /etc/nginx/sites-available/default</code></pre>
</figure>
<p>Take note of the root location, shown in the image below surrounded by the blue box. For the remainder of this tutorial, I’ll assume that your root location is located at <code>/var/www/html</code>. If it is not, make sure to switch your root location with mine when executing the commands below.</p>
<p>Then, add the contents below to the nginx configuration (surrounded by the red box in the image)</p>
<figure>
<pre><code data-lang="text">location ~ /.well-known {
    allow all;
}</code></pre>
</figure>
<p><img alt="" src="https://i2.wp.com/www.jasperginn.nl/assets/images/blog/shiny_series_pt3/setuppartIII.png?w=456&ssl=1" data-recalc-dims="1"></p>
<p>Restart nginx:</p>
<figure>
<pre><code data-lang="shell">sudo service nginx restart</code></pre>
</figure>
<p>Take your root location and your domain name (with www. and without it) and fill them out in the and </p>
<figure>
<pre><code data-lang="shell">certbot-auto certonly -a webroot --webroot-path<span>=</span>/var/www/html -d &lt;your-domain-name>.&lt;extension> -d www.&lt;your-domain-name>.&lt;extension></code></pre>
</figure>
<p>Next, we generate a strong <a target="_blank" rel="nofollow" href="https://en.wikipedia.org/wiki/Diffie%E2%80%93Hellman_key_exchange">Diffie–Hellman</a> group for extra security:</p>
<figure>
<pre><code data-lang="shell">sudo openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048</code></pre>
</figure>
<p>SSL certificates expire every couple of months or so, so it’s a good idea to refresh our certificate regularly. We’ll set up a cron job that does this every week. Access cron by executing the following:</p>
<figure>
<pre><code data-lang="shell">sudo crontab -e</code></pre>
</figure>
<p>Add the following lines:</p>
<figure>
<pre><code data-lang="text">30 2 * * 1 /usr/local/sbin/certbot-auto renew >> /var/log/le-renew.log
35 2 * * 1 /etc/init.d/nginx reload</code></pre>
</figure>
<p><img alt="" src="https://i0.wp.com/www.jasperginn.nl/assets/images/blog/shiny_series_pt3/crontab.png?w=456&ssl=1" data-recalc-dims="1"></p>
<p>Hit <code>control+x</code> and then <code>Y</code> and <code>enter</code>, and your changes will be saved. Congratulations, you have now successfully set up SSL encryption on your server! Note that SSL encryption is not yet operational; we’ll take care of that in the next part, when we’ll add user authentication to our private shiny server using <a target="_blank" rel="nofollow" href="https://auth0.com/">Auth0</a></p>
<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://www.jasperginn.nl/shiny-server-series-pt3/"> Jasper Ginn's blog</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/search/data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/search/map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/search/animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/search/sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/search/SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/search/git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/search/hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/search/PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/search/time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/search/trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/JfoF5mshzDU"></a></div>