{"id":5895,"date":"2021-06-16T23:02:38","date_gmt":"2021-06-16T23:02:38","guid":{"rendered":"https:\/\/www.geekdecoder.com\/?p=5895"},"modified":"2021-06-16T23:02:38","modified_gmt":"2021-06-16T23:02:38","slug":"setting-up-ipfs-server-with-nginx-and-gateway","status":"publish","type":"post","link":"https:\/\/www.qbytes.cloud\/index.php\/2021\/06\/16\/setting-up-ipfs-server-with-nginx-and-gateway\/","title":{"rendered":"Host a Web Site with a Domain on IPFS"},"content":{"rendered":"<p>This article describes how to host a web site on IPFS.<\/p>\n<p>Requirements:<br \/>\nAccess to a Registered Domain and DNS records.<br \/>\nEdit your DNS to point the A record to the IPFS server. We will need this to resolve in order to install a Let&#8217;s Encrypt Certificate.<\/p>\n<p>Lets Start with an Update<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n# sudo apt update \n# sudo apt upgrade -y\n<\/pre>\n<p>Lets create a new user account to run IPFS and switch to it:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n# adduser ipfs\n<\/pre>\n<p>Install sudo<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n# apt install sudo\n<\/pre>\n<p>Edit sudo and add the ipfs user<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n# visudo\n<\/pre>\n<p>Add the IPFS user below root<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n# User privilege specification\nroot    ALL=(ALL:ALL) ALL\nipfs    ALL=(ALL:ALL) ALL\n<\/pre>\n<p>change to the IPFS user.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n# su ipfs\n<\/pre>\n<p>Install IPFS<br \/>\nGet the latest release at <a href=\"https:\/\/dist.ipfs.tech\/#kubo\" target=\"_blank\" rel=\"noopener\">https:\/\/dist.ipfs.tech\/#kubo<\/a><\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n$ wget https:\/\/dist.ipfs.tech\/kubo\/v0.16.0\/kubo_v0.16.0_linux-amd64.tar.gz\n$ tar xfv kubo_v0.16.0_linux-amd64.tar.gz\n$ cd kubo\n.\/install.sh\n<\/pre>\n<p>Initialize IPFS:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n$ ipfs init --profile=server\n<\/pre>\n<p>Switch to the root user:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n$ exit\n<\/pre>\n<p>Allow the ipfs user to run long-running services by enabling user lingering for that user:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n# loginctl enable-linger ipfs\n<\/pre>\n<p>Create the file \/etc\/systemd\/system\/ipfs.service with this content:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n# nano \/etc\/systemd\/system\/ipfs.service\n<\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&#x5B;Unit]\nDescription=IPFS Daemon\nAfter=syslog.target network.target remote-fs.target nss-lookup.target\n&#x5B;Service]\nType=simple\nExecStart=\/usr\/local\/bin\/ipfs daemon --enable-namesys-pubsub\nUser=ipfs\n&#x5B;Install]\nWantedBy=multi-user.target\n<\/pre>\n<p>Enable and start the service:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n# systemctl enable ipfs\n# systemctl start ipfs\n<\/pre>\n<p>IPFS should be up and running, and start when the server boots.<\/p>\n<p>Check IPFS<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n$ su ipfs\n$ ipfs swarm peers\n<\/pre>\n<p>Add Website Files<\/p>\n<p>Create a folderfor your website files. Add this folder in the ipfs\/home directory<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n$ cd ~\n$ mkdir mysitefiles\n<\/pre>\n<p>Upload the site files to the directory. Now we can add these to IPFS with the following contect<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n$ ipfs add -r &lt;path&gt;\n<\/pre>\n<p>This adds all contents of the folder at to IPFS, recursively. You should see output similar to this:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n$ ipfs add -r mysitefiles\n<\/pre>\n<p>Output:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n ipfs add -r mysitefiles\/\nadded QmZrSe9TABdSsWL38FJTp4fW7TposFuzRLSBRYAEMVt1RE mysitefiles\/about.html\nadded Qmdf1mYmCjivJWcXpGikf87PV5VkBo6DQugsjq6GdNZ1az mysitefiles\/index.html\nadded QmW8U3NEHx3p73Nj9645sGnGa8XzR43rQh3Kd52UKncWMo mysitefiles\/moon-logo.png\nadded QmQ91HDqAt1eE7X4DHuJ9r74U3KgKN3pDGidLM6sadK2q2 mysitefiles\n 12.66 KiB \/ 12.66 KiB &#x5B;==================================================================================================] 100.00%\n<\/pre>\n<p>Each of the long sequence of numbers is called a Content Identifier or CID. These are cryptographically hashed. We can now check to see if the site loads. You can check and use an active gateway here: <a href=\"https:\/\/ipfs.github.io\/public-gateway-checker\/\" target=\"_blank\" rel=\"noopener\">https:\/\/ipfs.github.io\/public-gateway-checker\/<\/a><\/p>\n<p>Add the main Content Identifier (CID) folder ID to the URL. How to link to content on IPFS.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nhttps:\/\/ipfs.io\/ipfs\/&lt;CID&gt;\n# e.g\nhttps:\/\/ipfs.io\/ipfs\/QmQ91HDqAt1eE7X4DHuJ9r74U3KgKN3pDGidLM6sadK2q2\n<\/pre>\n<p>Now we can set up the DNS records. See: <a href=\"https:\/\/dnslink.io\/#introduction\" target=\"_blank\" rel=\"noopener\">https:\/\/dnslink.io\/#introduction<\/a><\/p>\n<p>Login to manage your DNS. Add the following TXT Record:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ndnslink=\/ipfs\/QmQ91HDqAt1eE7X4DHuJ9r74U3KgKN3pDGidLM6sadK2q2\n<\/pre>\n<p>Here is my Namecheap DNS<br \/>\n<a href=\"https:\/\/qbytes.cloud\/wp-content\/uploads\/2021\/06\/Screenshot-2022-10-04-172832.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-6723\" src=\"https:\/\/qbytes.cloud\/wp-content\/uploads\/2021\/06\/Screenshot-2022-10-04-172832-1024x71.png\" alt=\"\" width=\"640\" height=\"44\" srcset=\"https:\/\/www.qbytes.cloud\/wp-content\/uploads\/2021\/06\/Screenshot-2022-10-04-172832-1024x71.png 1024w, https:\/\/www.qbytes.cloud\/wp-content\/uploads\/2021\/06\/Screenshot-2022-10-04-172832-300x21.png 300w, https:\/\/www.qbytes.cloud\/wp-content\/uploads\/2021\/06\/Screenshot-2022-10-04-172832-768x53.png 768w, https:\/\/www.qbytes.cloud\/wp-content\/uploads\/2021\/06\/Screenshot-2022-10-04-172832.png 1136w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<p>Install nginx with Let&#8217;s Encrypt SSL certs<br \/>\nChange to root<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n$ su root \n<\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n# apt-get update\n# apt-get install nginx\n<\/pre>\n<p>Check status to make sure it started and is not throwing any errors:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">$ systemctl status nginx\n<\/pre>\n<p>Results<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\u25cf nginx.service - A high performance web server and a reverse proxy server\n   Loaded: loaded (\/lib\/systemd\/system\/nginx.service; enabled; vendor preset: en\n   Active: active (running) since Wed 2021-06-16 22:59:51 UTC; 1min 44s ago\n     Docs: man:nginx(8)\n  Process: 13062 ExecStartPre=\/usr\/sbin\/nginx -t -q -g daemon on; master_process\n  Process: 13063 ExecStart=\/usr\/sbin\/nginx -g daemon on; master_process on; (cod\n Main PID: 13064 (nginx)\n    Tasks: 2 (limit: 1163)\n   Memory: 5.3M\n   CGroup: \/system.slice\/nginx.service\n           \u251c\u250013064 nginx: master process \/usr\/sbin\/nginx -g daemon on; master_pr\n           \u2514\u250013065 nginx: worker process\n\nJun 16 22:59:51 ip-10-0-1-209 systemd&#x5B;1]: Starting A high performance web server\nJun 16 22:59:51 ip-10-0-1-209 systemd&#x5B;1]: nginx.service: Failed to parse PID fro\nJun 16 22:59:51 ip-10-0-1-209 systemd&#x5B;1]: Started A high performance web server\nlines 1-16\/16 (END)\n\n<\/pre>\n<p>Get your IP and open it with browser to make sure Nginx is serving its default page:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">$ curl -s domain.com\n$ curl -s Ip_address\n<\/pre>\n<p>Now browse to http:\/\/your-ip-here and you should see the Nginx default page &#8220;Welcome to Nginx&#8221;.<\/p>\n<p><a href=\"https:\/\/qbytes.cloud\/wp-content\/uploads\/2021\/06\/nginx1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-5898 size-medium\" src=\"https:\/\/qbytes.cloud\/wp-content\/uploads\/2021\/06\/nginx1-300x118.png\" alt=\"\" width=\"300\" height=\"118\" srcset=\"https:\/\/www.qbytes.cloud\/wp-content\/uploads\/2021\/06\/nginx1-300x118.png 300w, https:\/\/www.qbytes.cloud\/wp-content\/uploads\/2021\/06\/nginx1.png 649w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Set Up your nginx configs:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">$ sudo mv \/etc\/nginx\/sites-available\/default \/etc\/nginx\/sites-available\/default_back\n# sudo nano \/etc\/nginx\/sites-available\/default\n<\/pre>\n<p>Copy and paste this config (change example.com to your domain)<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n\nserver {\n    server_name example.com www.example.com;\n    server_tokens off;\n\n    listen 80;\n    listen &#x5B;::]:80;\n    listen 443 ssl;\n    listen &#x5B;::]:443 ssl;\n\n    location \/ {\n        proxy_pass http:\/\/localhost:8080;\n        proxy_http_version 1.1;\n        proxy_set_header Upgrade $http_upgrade;\n        proxy_set_header Connection 'upgrade';\n        proxy_set_header Host $host;\n        proxy_cache_bypass $http_upgrade;\n    }\n}\n<\/pre>\n<p>Test that new config syntax and make sure it is ok:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">$ sudo nginx -t\n<\/pre>\n<p>If all good reload:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">$ sudo systemctl reload nginx\n<\/pre>\n<p>Add Lets Encrypt according to this article &#8211; <a href=\"https:\/\/www.geekdecoder.com\/set-up-lets-encrypt-on-debian-10\/\" target=\"_blank\" rel=\"noopener\">https:\/\/www.geekdecoder.com\/set-up-lets-encrypt-on-debian-10\/<\/a><\/p>\n<p>The final config should resemble this:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nserver {\n    server_name example.com www.example.com;\n    server_tokens off;\n\n    location \/ {\n        proxy_pass http:\/\/localhost:8080;\n        proxy_http_version 1.1;\n        proxy_set_header Upgrade $http_upgrade;\n        proxy_set_header Connection 'upgrade';\n        proxy_set_header Host $host;\n        proxy_cache_bypass $http_upgrade;\n    }\n\n    listen &#x5B;::]:443 ssl ipv6only=on; # managed by Certbot\n    listen 443 ssl; # managed by Certbot\n    ssl_certificate \/etc\/letsencrypt\/live\/example.com\/fullchain.pem; # managed by Certbot\n    ssl_certificate_key \/etc\/letsencrypt\/live\/example.com\/privkey.pem; # managed by Certbot\n    include \/etc\/letsencrypt\/options-ssl-nginx.conf; # managed by Certbot\n    ssl_dhparam \/etc\/letsencrypt\/ssl-dhparams.pem; # managed by Certbot\n\n}\nserver {\n    if ($host = www.example.com) {\n        return 301 https:\/\/$host$request_uri;\n    } # managed by Certbot\n\n\n    if ($host = example.com) {\n        return 301 https:\/\/$host$request_uri;\n    } # managed by Certbot\n\n\n    server_name example.com www.example.com;\n\n    listen 80;\n    listen &#x5B;::]:80;\n    return 404; # managed by Certbot\n}\n<\/pre>\n<p>The site should now be available.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This article describes how to host a web site on IPFS. Requirements: Access to a Registered Domain and DNS records. Edit your DNS to point the A record to the IPFS server. We will need this to resolve in order to install a Let&#8217;s Encrypt Certificate. Lets Start with an Update # sudo apt update &#8230; <a title=\"Host a Web Site with a Domain on IPFS\" class=\"read-more\" href=\"https:\/\/www.qbytes.cloud\/index.php\/2021\/06\/16\/setting-up-ipfs-server-with-nginx-and-gateway\/\" aria-label=\"Read more about Host a Web Site with a Domain on IPFS\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[74],"tags":[],"class_list":["post-5895","post","type-post","status-publish","format-standard","hentry","category-nginx"],"_links":{"self":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts\/5895","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/comments?post=5895"}],"version-history":[{"count":0,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/posts\/5895\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/media?parent=5895"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/categories?post=5895"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.qbytes.cloud\/index.php\/wp-json\/wp\/v2\/tags?post=5895"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}