{"id":273,"date":"2018-05-26T13:31:23","date_gmt":"2018-05-26T05:31:23","guid":{"rendered":"https:\/\/www.techcoil.com\/blog\/?p=273"},"modified":"2018-10-13T22:23:27","modified_gmt":"2018-10-13T14:23:27","slug":"how-to-configure-nginx-on-raspberry-pi-3-as-a-reverse-proxy-server-for-synology-diskstation-manager","status":"publish","type":"post","link":"https:\/\/www.techcoil.com\/blog\/how-to-configure-nginx-on-raspberry-pi-3-as-a-reverse-proxy-server-for-synology-diskstation-manager\/","title":{"rendered":"How to configure Nginx on Raspberry Pi 3 as a reverse proxy server for Synology DiskStation Manager"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/raspberry-pi-proxy-synology-dsm-network-architecture.gif\" alt=\"Raspberry Pi proxy Synology DSM network architecture\"\/><\/p>\n<p>When you get a Synology NAS like <a href=\"https:\/\/www.amazon.com\/Synology-bay-DiskStation-DS218j-Diskless\/dp\/B076G6YKWZ\/ref=as_li_ss_tl?ie=UTF8&qid=1527143282&sr=8-3&keywords=synology+ds218j&linkCode=ll1&tag=clivsperswebs-20&linkId=9330aaa01efaf2e20ecab889f1ce2d85\" rel=\"noopener\" target=\"_blank\">DS218j<\/a> or <a href=\"https:\/\/www.amazon.com\/Synology-bay-DiskStation-DS418-Diskless\/dp\/B075N17DM6\/ref=as_li_ss_tl?s=electronics&ie=UTF8&qid=1527144593&sr=1-1&keywords=ds418&linkCode=ll1&tag=clivsperswebs-20&linkId=dd272e76c7dc540efb1a368351fbfab4\" rel=\"noopener\" target=\"_blank\">DS418<\/a>, you will also get the Synology DiskStation Manager. Eventually, you may want to access websites other than Synology DiskStation Manager from outside your home. In that case, you may want to use Nginx as a <a href=\"https:\/\/www.techcoil.com\/blog\/the-reverse-proxy-server\/\" rel=\"noopener\" target=\"_blank\">reverse proxy server<\/a> for your websites. <\/p>\n<p>Without a doubt, <a href=\"https:\/\/www.amazon.com\/ELEMENT-Element14-Raspberry-Pi-Motherboard\/dp\/B07BDR5PDW\/ref=as_li_ss_tl?s=pc&ie=UTF8&qid=1527081371&sr=1-13&keywords=Raspberry+Pi+3&linkCode=ll1&tag=clivsperswebs-20&linkId=f55e824cdf88468418efca4bac3b1a47\" rel=\"noopener\" target=\"_blank\">Raspberry Pi 3<\/a> is one <a href=\"https:\/\/www.techcoil.com\/glossary\/single-board-computer\/\" rel=\"noopener\" target=\"_blank\">single-board computer<\/a> that packs enough computing power for many use cases. For example, you can <a href=\"https:\/\/www.techcoil.com\/blog\/building-a-reverse-proxy-server-with-nginx-certbot-raspbian-stretch-lite-and-raspberry-pi-3\/\" rel=\"noopener\" target=\"_blank\">setup a Raspberry Pi 3 reverse proxy server with Nginx, Certbot, Raspbian Stretch Lite<\/a>. Thereafter, you will be able to <a href=\"https:\/\/www.techcoil.com\/blog\/how-to-host-multiple-websites-from-home\/\" rel=\"noopener\" target=\"_blank\">host multiple websites from home<\/a>.<\/p>\n<p>In case you have both a Raspberry Pi 3 and a Synology NAS, read on to see how you can configure Nginx on Raspberry Pi 3 as a reverse proxy for Synology DiskStation Manager.<\/p>\n<h2>Setting up a reverse proxy server with Nginx, Certbot, Raspbian Stretch Lite and Raspberry Pi 3<\/h2>\n<p>In case you had not setup Nginx on Raspberry Pi 3 at home, <a href=\"https:\/\/www.techcoil.com\/blog\/building-a-reverse-proxy-server-with-nginx-certbot-raspbian-stretch-lite-and-raspberry-pi-3\/\" rel=\"noopener\" target=\"_blank\">follow this guide to setup one on Raspberry Pi 3 reverse proxy server<\/a>. After you had followed the steps till the section on installing Certbot, you will have a Raspberry Pi 3 reverse proxy server with <a href=\"https:\/\/nginx.org\/\" rel=\"noopener\" target=\"_blank\">Nginx<\/a> and <a href=\"http:\/\/certbot.eff.org\" rel=\"noopener\" target=\"_blank\">Certbot<\/a> installed. <\/p>\n<h2>Setting up a web directory for ACME challenges for validating domain to reach Synology DiskStation Manager<\/h2>\n<p>During the validation of domain by <a href=\"https:\/\/letsencrypt.org\/\" rel=\"noopener\" target=\"_blank\">Let's Encrypt<\/a> servers, <a href=\"https:\/\/ietf-wg-acme.github.io\/acme\/draft-ietf-acme-acme.html\" rel=\"noopener\" target=\"_blank\">ACME<\/a> challenges will need to be created in a web directory and accessed via the domain. <\/p>\n<p>For the purpose of this guide, let's suppose that you <\/p>\n<ol>\n<li>want to access your Synology DiskStation Manager via <strong>nas.yourdomain.com<\/strong>,<\/li>\n<li>had created the relevant configurations for <strong>nas.yourdomain.com<\/strong> to be mapped to the public IP address that your <a href=\"https:\/\/www.amazon.com\/s\/ref=as_li_ss_tl?url=search-alias=aps&field-keywords=home+router&linkCode=ll2&tag=clivsperswebs-20&linkId=648ab141c4be5ffb7c4fd642eb2823dd\" rel=\"noopener\" target=\"_blank\">home router<\/a> had gotten from your ISP. If the public IP address changes frequently, you may want to <a href=\"https:\/\/namecheap.pxf.io\/c\/1303251\/386170\/5618?u=https%3A%2F%2Fwww.namecheap.com%2Fdomains%2Fdomain-name-search.aspx\" rel=\"noopener\" target=\"_blank\">buy a Namecheap domain<\/a> and <a href=\"https:\/\/www.techcoil.com\/blog\/how-to-get-your-raspberry-pi-3-to-use-namecheap-dynamic-dns-to-update-your-domain-when-your-homes-public-ip-address-changes\/\" rel=\"noopener\" target=\"_blank\">get your Raspberry Pi 3 to use Namecheap dynamic DNS to update your domain when your home\u2019s public IP address changes<\/a>.<\/li>\n<li>had configured your router to forward port <strong>80<\/strong> and port <strong>443<\/strong> to your Raspberry Pi 3. <\/li>\n<\/ol>\n<p>In case you need a reference, <a href=\"https:\/\/www.techcoil.com\/blog\/host-web-server-behind-linksys-ea7500-max-stream-ac1900-router\/\" rel=\"noopener\" target=\"_blank\">this is how you can host a web server behind Linksys EA7500 Max-Stream AC1900 router<\/a>.<\/p>\n<p>Given these points, run the following commands to setup a web directory for Synology DiskStation Manager in your Raspberry Pi 3:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsudo mkdir \/www\/var\/nas.yourdomain.com\r\nsudo chown www-data:www-data \/www\/var\/nas.yourdomain.com\r\n<\/pre>\n<p>After creating the directory and changing the owner to the <code>www-data<\/code> user, proceed to create a Nginx configuration at <strong><code>\/etc\/nginx\/sites-enabled\/nas.yourdomain.com.conf<\/code><\/strong>:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsudo nano \/etc\/nginx\/sites-enabled\/nas.yourdomain.com.conf\r\n<\/pre>\n<p>Once the nano editor loads, write the following content into the editor:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nserver {\r\n    listen 80;\r\n    server_name  nas.yourdomain.com;\r\n \r\n    root \/var\/www\/nas.yourdomain.com;\r\n \r\n    location ~ \/.well-known {\r\n        allow all;\r\n    }\r\n}\r\n<\/pre>\n<p>Thereafter, save the file by typing <strong>Ctrl-X<\/strong> followed by <strong>Y<\/strong>. <\/p>\n<p>After that, run the following command to restart Nginx:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsudo systemctl restart nginx.service\r\n<\/pre>\n<h2>Running Certbot to acquire the Let's Encrypt artefacts that are needed for serving HTTPS traffic for Synology DiskStation Manager<\/h2>\n<p>Once you had configured Nginx to facilitate the ACME challenge process, run Certbot to acquire the artefacts that are needed for serving HTTPS traffic for Synology DiskStation Manager:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsudo certbot certonly -a webroot --webroot-path=\/var\/www\/nas.yourdomain.com -d nas.yourdomain.com\r\n<\/pre>\n<p>After the command completes, you will find Let's Encrypt artefacts inside <code>\/etc\/letsencrypt\/live\/nas.yourdomain.com<\/code>. <\/p>\n<h2>Configuring Nginx to serve HTTPS traffic for Synology DiskStation Manager<\/h2>\n<p>In case you had not already computed a Diffie-Hellman group for Nginx to use for exchanging cryptographic keys with its clients, run the following command to generate one:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsudo openssl dhparam -out \/etc\/ssl\/certs\/dhparam.pem 2048\r\n<\/pre>\n<p>This process will take some time to complete.<\/p>\n<p>Given that your Synology DiskStation Manager is accessible via <code>192.168.1.123:5000<\/code>, let's proceed with configuring Nginx to proxy HTTPS traffic to it. Firstly, open up <code>\/etc\/nginx\/sites-enabled\/nas.yourdomain.com.conf<\/code><\/strong> with <code>nano<\/code>:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsudo nano \/etc\/nginx\/sites-enabled\/nas.yourdomain.com.conf\r\n<\/pre>\n<p>After nano editor loads the file, replace the contents with the following:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n# Redirect HTTP requests to HTTPS \r\nserver {\r\n    listen 80;\r\n    server_name  nas.yourdomain.com;\r\n    return 301 https:\/\/$host$request_uri;\r\n}\r\n  \r\n# For ssl\r\nserver {\r\n    client_max_body_size 8M;\r\n\r\n    ssl on;\r\n    ssl_certificate \/etc\/letsencrypt\/live\/nas.yourdomain.com\/fullchain.pem;\r\n    ssl_certificate_key \/etc\/letsencrypt\/live\/nas.yourdomain.com\/privkey.pem;\r\n    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;\r\n    ssl_prefer_server_ciphers on;\r\n    ssl_dhparam \/etc\/ssl\/certs\/dhparam.pem;\r\n    ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA';\r\n    ssl_session_timeout 1d;\r\n    ssl_session_cache shared:SSL:50m;\r\n    ssl_stapling on;\r\n    ssl_stapling_verify on;\r\n    add_header Strict-Transport-Security max-age=15768000;\r\n      \r\n    default_type  application\/octet-stream;\r\n      \r\n    listen 443;\r\n    server_name  nas.yourdomain.com;\r\n  \r\n    root \/var\/www\/nas.yourdomain.com;\r\n  \r\n    location ~ \/.well-known {\r\n        allow all;\r\n    }\r\n  \r\n    location \/ {\r\n        proxy_pass http:\/\/192.168.1.123:5000;\r\n    }\r\n}\r\n<\/pre>\n<p>Thereafter, save the file by typing <strong>Ctrl-X<\/strong> followed by <strong>Y<\/strong>. <\/p>\n<p>After that, run the following command to restart Nginx:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsudo systemctl restart nginx.service\r\n<\/pre>\n<p>When your Nginx had restarted successfully, you will be able to access your Synology DiskStation Manager at <code>nas.yourdomain.com<\/code> via HTTPS.<\/p>\n<h2>Renewing the Let's Encrypt SSL certificate for nas.yourdomain.com in the future<\/h2>\n<p>Eventually, your Let's Encrypt SSL certificate will expire. In that case, you can renew your SSL certificate for nas.yourdomain.com with the following command:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsudo certbot certonly --force-renewal -a webroot --webroot-path=\/var\/www\/nas.yourdomain.com -d nas.yourdomain.com\r\n<\/pre>\n<h2>Solving: Failed to upload \"<your_file>\". Connection failed. Please check your network settings.<\/h2>\n<p>When you encounter the message:<\/p>\n<blockquote><p>\nFailed to upload \"<your_file>\". Connection failed. Please check your network settings.\n<\/p><\/blockquote>\n<p>while uploading your file, it could be that the file had exceeded 8MB. In this case, update the <a href=\"http:\/\/nginx.org\/en\/docs\/http\/ngx_http_core_module.html#client_max_body_size\" rel=\"noopener\" target=\"_blank\">client_max_body_size  directive<\/a> to take a larger value. After you had changed the value in <code>\/etc\/nginx\/sites-enabled\/nas.yourdomain.com.conf<\/code>, restart Nginx with the following command:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsudo systemctl restart nginx.service\r\n<\/pre>\n\n      <ul id=\"social-sharing-buttons-list\">\n        <li class=\"facebook\">\n          <a href=\"https:\/\/www.facebook.com\/sharer\/sharer.php?u=https%3A%2F%2Fwp.me%2Fp245TQ-4p\" target=\"_blank\" role=\"button\" rel=\"nofollow\">\n            <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/Facebook.png\" alt=\"Facebook icon\"> Share\n          <\/a>\n        <\/li>\n        <li class=\"twitter\">\n          <a href=\"https:\/\/twitter.com\/intent\/tweet?text=&url=https%3A%2F%2Fwp.me%2Fp245TQ-4p&via=Techcoil_com\" target=\"_blank\" role=\"button\" rel=\"nofollow\">\n          <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/Twitter.png\" alt=\"Twitter icon\"> Tweet\n          <\/a>\n        <\/li>\n        <li class=\"linkedin\">\n          <a href=\"https:\/\/www.linkedin.com\/shareArticle?mini=1&title=&url=https%3A%2F%2Fwp.me%2Fp245TQ-4p&source=https:\/\/www.techcoil.com\" target=\"_blank\" role=\"button\" rel=\"nofollow\">\n          <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/linkedin.png\" alt=\"Linkedin icon\"> Share\n          <\/a>\n        <\/li>\n        <li class=\"pinterest\">\n          <a href=\"https:\/\/pinterest.com\/pin\/create\/button\/?url=https%3A%2F%2Fwww.techcoil.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F273&description=\" class=\"pin-it-button\" target=\"_blank\" role=\"button\" rel=\"nofollow\" count-layout=\"horizontal\">\n          <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/Pinterest.png\" alt=\"Pinterest icon\"> Save\n          <\/a>\n        <\/li>\n      <\/ul>\n    ","protected":false},"excerpt":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/raspberry-pi-proxy-synology-dsm-network-architecture.gif\" alt=\"Raspberry Pi proxy Synology DSM network architecture\"\/><\/p>\n<p>When you get a Synology NAS like <a href=\"https:\/\/www.amazon.com\/Synology-bay-DiskStation-DS218j-Diskless\/dp\/B076G6YKWZ\/ref=as_li_ss_tl?ie=UTF8&#038;qid=1527143282&#038;sr=8-3&#038;keywords=synology+ds218j&#038;linkCode=ll1&#038;tag=clivsperswebs-20&#038;linkId=9330aaa01efaf2e20ecab889f1ce2d85\" rel=\"noopener\" target=\"_blank\">DS218j<\/a> or <a href=\"https:\/\/www.amazon.com\/Synology-bay-DiskStation-DS418-Diskless\/dp\/B075N17DM6\/ref=as_li_ss_tl?s=electronics&#038;ie=UTF8&#038;qid=1527144593&#038;sr=1-1&#038;keywords=ds418&#038;linkCode=ll1&#038;tag=clivsperswebs-20&#038;linkId=dd272e76c7dc540efb1a368351fbfab4\" rel=\"noopener\" target=\"_blank\">DS418<\/a>, you will also get the Synology DiskStation Manager. Eventually, you may want to access websites other than Synology DiskStation Manager from outside your home. In that case, you may want to use Nginx as a <a href=\"https:\/\/www.techcoil.com\/blog\/the-reverse-proxy-server\/\" rel=\"noopener\" target=\"_blank\">reverse proxy server<\/a> for your websites. <\/p>\n<p>Without a doubt, <a href=\"https:\/\/www.amazon.com\/ELEMENT-Element14-Raspberry-Pi-Motherboard\/dp\/B07BDR5PDW\/ref=as_li_ss_tl?s=pc&#038;ie=UTF8&#038;qid=1527081371&#038;sr=1-13&#038;keywords=Raspberry+Pi+3&#038;linkCode=ll1&#038;tag=clivsperswebs-20&#038;linkId=f55e824cdf88468418efca4bac3b1a47\" rel=\"noopener\" target=\"_blank\">Raspberry Pi 3<\/a> is one <a href=\"https:\/\/www.techcoil.com\/glossary\/single-board-computer\/\" rel=\"noopener\" target=\"_blank\">single-board computer<\/a> that packs enough computing power for many use cases. For example, you can <a href=\"https:\/\/www.techcoil.com\/blog\/building-a-reverse-proxy-server-with-nginx-certbot-raspbian-stretch-lite-and-raspberry-pi-3\/\" rel=\"noopener\" target=\"_blank\">setup a Raspberry Pi 3 reverse proxy server with Nginx, Certbot, Raspbian Stretch Lite<\/a>. Thereafter, you will be able to <a href=\"https:\/\/www.techcoil.com\/blog\/how-to-host-multiple-websites-from-home\/\" rel=\"noopener\" target=\"_blank\">host multiple websites from home<\/a>.<\/p>\n<p>In case you have both a Raspberry Pi 3 and a Synology NAS, read on to see how you can configure Nginx on Raspberry Pi 3 as a reverse proxy for Synology DiskStation Manager.<\/p>\n","protected":false},"author":1,"featured_media":1009,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"footnotes":""},"categories":[4],"tags":[431,266,225,240,308,412,445,531,532,438],"jetpack_featured_media_url":"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/raspberry-pi-proxy-synology-dsm-network-architecture.gif","jetpack_shortlink":"https:\/\/wp.me\/p245TQ-4p","jetpack-related-posts":[],"jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/posts\/273"}],"collection":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/comments?post=273"}],"version-history":[{"count":0,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/posts\/273\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/media\/1009"}],"wp:attachment":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/media?parent=273"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/categories?post=273"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/tags?post=273"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}