{"id":11,"date":"2023-08-19T11:06:53","date_gmt":"2023-08-19T11:06:53","guid":{"rendered":"https:\/\/www.dbaldwin.net\/?p=11"},"modified":"2023-08-21T21:31:00","modified_gmt":"2023-08-21T21:31:00","slug":"setting-up-an-nginx-webserver-on-alma-linux-9-step-by-step","status":"publish","type":"post","link":"https:\/\/www.dbaldwin.net\/?p=11","title":{"rendered":"Setting up an Nginx Webserver on Alma Linux 9 &#8211; Step by Step"},"content":{"rendered":"\n<p><em><strong>Note: Although this was wrote for Alma Linux, its highly likely most, if not all, of the commands will work for most of the other Red-Hat based family of Linux distros.<\/strong><\/em><\/p>\n\n\n\n<p>I have written this guide step by step and dealing with one section at a time and as a result it is more long-winded than it needs to be. This could be condensed down into less commands by combining the different parts and doing them together such as the packages installs.  However I have left it in a longer form to make it clear what the different steps that are involved are for people who are learning.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Install Nginx<\/h3>\n\n\n\n<p>Don&#8217;t forget to update the server<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo dnf update -y<\/code><\/pre>\n\n\n\n<p>The first step is to to pull down and install the Nginx web server. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo dnf install nginx -y<\/code><\/pre>\n\n\n\n<p>Once Nginx has come down and been installed onto the machine you need to start &amp; enable it to load on reboot:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl enable nginx\nsudo systemctl start nginx<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Open up firewall ports<\/h3>\n\n\n\n<p>Whether you are hosting yourself or running a VM in the cloud there are likely two different firewalls you need to approve the HTTP &amp; HTTPS traffic through. The machine itself as well as the network firewall.<\/p>\n\n\n\n<p>On your network firewall you need to allow TCP traffic through on ports 80 (HTTP) &amp; 443 (HTTPS). You also need to allow traffic through your device firewall. To do this you need to add the following rules to firewalld your Alma Linux install.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo firewall-cmd --zone=public --add-service=http --permanent\n\nsudo firewall-cmd --zone=public --add-service=https --permanent\n\n sudo firewall-cmd --reload\n<\/code><\/pre>\n\n\n\n<p>Once you have done this you should find that you can load the default Nginx page in your web browser by going to the computer&#8217;s public IP address. Note that it isn&#8217;t secure as you have not yet enabled SSL\/TLS<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"793\" height=\"673\" src=\"https:\/\/www.dbaldwin.net\/wp-content\/uploads\/2023\/08\/Alma-Linux-Test-Page.png\" alt=\"\" class=\"wp-image-21\"\/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Set your domain address to point to our server.<\/h3>\n\n\n\n<p>We need to set our domain address to have an A record to point to our server. It can take some time for the change to propagate around all the DNS servers across the internet. You may wish to also add a C Name for www. and point it to your A record.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"1506\" height=\"162\" src=\"https:\/\/www.dbaldwin.net\/wp-content\/uploads\/2023\/08\/DNS-A-Record.png\" alt=\"\" class=\"wp-image-12\"\/><\/figure>\n\n\n\n<p>On your personal computer you can use the dig or nslookup command to check if your DNS server records have changed and now points to your server&#8217;s IP address.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"1274\" height=\"692\" src=\"https:\/\/www.dbaldwin.net\/wp-content\/uploads\/2023\/08\/dig-1.png\" alt=\"\" class=\"wp-image-33\"\/><\/figure>\n\n\n\n<p>Once your DNS server has updated you should be able to load the Nginx test page via your domain name in your web browser.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Configuring Nginx to use our domain name<\/h3>\n\n\n\n<p>We need to edit some Nginx configuration files to enter in our domain name. I found my minimal version of Alma Linux does not have Nano installed so I had to use vi(m) for my text editing. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo vi \/etc\/nginx\/nginx.conf<\/code><\/pre>\n\n\n\n<p><em>If you are unfamiliar with vi\/vim  you need to learn a few key commands. Once it is open use the i key to enter edit mode. Once you are done with your edits and want to save press esc then type :wq (write and quit). If you have made a mistake and <strong>don&#8217;t <\/strong>want to save your changes type :q!<\/em><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"1198\" height=\"558\" src=\"https:\/\/www.dbaldwin.net\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-19-at-11.37.51.png\" alt=\"\" class=\"wp-image-23\"\/><\/figure>\n\n\n\n<p>You can choose to change your website root here as well, however be aware that doing so you may experience permission issues with SElinux that you would need to resolve.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Setting UP HTTPS using Letsencrypt &amp; Certbot<\/h3>\n\n\n\n<p>Probably the easiest way to get a TLS\/SSL certificate is to use certbot, however we need to add the Extra Packages for Enterprise Linux Repository. Thankfully this is simple by using one command.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo dnf install epel-release -y<\/code><\/pre>\n\n\n\n<p>Now we can install Certbot and the required Nginx plugin<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo dnf install certbot python3-certbot-nginx -y<\/code><\/pre>\n\n\n\n<p>Now that certbot has installed we can setup TLS encryption for our server:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo certbot --nginx<\/code><\/pre>\n\n\n\n<p>It will as you for an email address for urgent renewal notifications, feel free to enter an address you check regularly, then you will have to agree to the T&amp;C&#8217;s and choose if you wish to join their mailing list. Finally you should be presented with your domain name to request a certificate for. you can just press enter here, or select the number.<\/p>\n\n\n\n<p>You should get a message congratulating you for enabling HTTPS on your site, now you need to restart your Nginx server to allow it to start using your new certificate:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl restart nginx<\/code><\/pre>\n\n\n\n<p>Optionally we can set Letsencrypt to auto renew the TLS certificates so that we don&#8217;t have to do this manually.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl start certbot-renew.timer &amp;&amp; sudo systemctl enable certbot-renew.timer<\/code><\/pre>\n\n\n\n<p>That&#8217;s it! Congratulations your Nginx web server should be setup and working and you should now be ready to host your site.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Note: Although this was wrote for Alma Linux, its highly likely most, if not all, of the commands will work for most of the other Red-Hat based family of Linux distros. I have written this guide step by step and dealing with one section at a time and as a result it is more long-winded &#8230; <a title=\"Setting up an Nginx Webserver on Alma Linux 9 &#8211; Step by Step\" class=\"read-more\" href=\"https:\/\/www.dbaldwin.net\/?p=11\" aria-label=\"More on Setting up an Nginx Webserver on Alma Linux 9 &#8211; Step by Step\">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":[2],"tags":[4,6,3,5],"_links":{"self":[{"href":"https:\/\/www.dbaldwin.net\/index.php?rest_route=\/wp\/v2\/posts\/11"}],"collection":[{"href":"https:\/\/www.dbaldwin.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dbaldwin.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dbaldwin.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dbaldwin.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=11"}],"version-history":[{"count":11,"href":"https:\/\/www.dbaldwin.net\/index.php?rest_route=\/wp\/v2\/posts\/11\/revisions"}],"predecessor-version":[{"id":35,"href":"https:\/\/www.dbaldwin.net\/index.php?rest_route=\/wp\/v2\/posts\/11\/revisions\/35"}],"wp:attachment":[{"href":"https:\/\/www.dbaldwin.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=11"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dbaldwin.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=11"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dbaldwin.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=11"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}