{"id":5366,"date":"2023-10-13T07:55:09","date_gmt":"2023-10-13T07:55:09","guid":{"rendered":"https:\/\/natsav.com\/blog\/?p=5366"},"modified":"2024-02-12T12:46:11","modified_gmt":"2024-02-12T12:46:11","slug":"setup-nginx-on-ubuntu-server-9","status":"publish","type":"post","link":"https:\/\/natsav.com\/blog\/setup-nginx-on-ubuntu-server-9\/","title":{"rendered":"How to Setup Nginx HTTP Server on Ubuntu 18.04 LTS Server #9"},"content":{"rendered":"\r\n<p><strong><span style=\"color: #0000ff;\">Step 1:<\/span> Updating Ubuntu Server<\/strong><\/p>\r\n\r\n\r\n\r\n<p>sudo apt update<\/p>\r\n\r\n\r\n\r\n<p><strong>Step 2: Installing Nginx on Ubuntu Server<\/strong><\/p>\r\n\r\n\r\n\r\n<p>sudo apt install nginx<\/p>\r\n\r\n\r\n\r\n<p><strong>Step 3: Managing Nginx Web Server<\/strong><\/p>\r\n\r\n\r\n\r\n<p><strong>\u2014 Stops the server:\u00a0<\/strong><\/p>\r\n\r\n\r\n\r\n<p>sudo systemctl stop nginx.service<\/p>\r\n\r\n\r\n\r\n<p><strong>\u2014 Start the server:\u00a0<\/strong><\/p>\r\n\r\n\r\n\r\n<p>sudo systemctl start nginx.service<\/p>\r\n\r\n\r\n\r\n<p><strong>\u2014 Restarts the server:<\/strong><\/p>\r\n\r\n\r\n\r\n<p>sudo systemctl restart nginx.service<\/p>\r\n\r\n\r\n\r\n<p><strong>\u2014 Reload config changes no stops:\u00a0<\/strong><\/p>\r\n\r\n\r\n\r\n<p>sudo systemctl reload nginx.service<\/p>\r\n\r\n\r\n\r\n<p><strong>Step 4: Configure Nginx Server<\/strong><\/p>\r\n\r\n\r\n\r\n<p>When <a href=\"https:\/\/natsav.com\/blog\/install-nginx-on-ubuntu\/\"><strong>Nginx is install on Ubuntu<\/strong><\/a> servers, the default document root directory is located at <strong>\/var\/www\/html <\/strong>Just as with Apache2 server on Ubuntu.<\/p>\r\n\r\n\r\n\r\n<p>The majority of <strong>Nginx configurations files<\/strong> are stored in <strong>\/etc\/nginx<\/strong> directory.<\/p>\r\n\r\n\r\n\r\n<p>Two important locations you\u2019ll spend most of your time are <strong>\/etc\/nginx\/sites-available <\/strong>and <strong>\/etc\/nginx\/sites-enabled<\/strong><\/p>\r\n\r\n\r\n\r\n<p>The sites-available directory contains all the available sites. This is the location you create new site configuration files, and sites-enabled directory contains all sites that are enabled. By default, sites are not enabled until you run commands to enable them.<\/p>\r\n\r\n\r\n\r\n<p>The first default site configuration file is <strong>\/etc\/nginx\/sites-available\/default<\/strong><\/p>\r\n\r\n\r\n\r\n<p><strong>Step 5: Enabling and Disabling Nginx Sites<\/strong><\/p>\r\n\r\n\r\n\r\n<p>After creating Nginx sites on Ubuntu something to remember is to always enable the sites. With Apache2, we showed you how to do that. Sites can be enabled by running the <strong>a2ensite <\/strong>and disable by running the <strong>a2dissite<\/strong> commands<\/p>\r\n\r\n\r\n\r\n<p>Nginx does not have these available. So to enable a site named example.com on Ubuntu for Nginx, just create a symbolic link from the sites-available to the sites-enabled directory.<\/p>\r\n\r\n\r\n\r\n<p><strong>sudo ln -s \/etc\/nginx\/sites-available\/example.com \/etc\/nginx\/sites-enabled\/example.com<\/strong><\/p>\r\n\r\n\r\n\r\n<p>To disable the example.com site, just delete it from the sites-enabled directory.<\/p>\r\n\r\n\r\n\r\n<p><strong>sudo rm \/etc\/nginx\/sites-enabled\/example.com<\/strong><\/p>\r\n\r\n\r\n\r\n<p>After enabling or disabling a site, restart Nginx server.<\/p>\r\n\r\n\r\n\r\n<p><strong>sudo systemctl restart nginx.service<\/strong> To test if Nginx is installed and working, open your browser and browse to the server IP or hostname and you should see Nginx default page if it was installed properly.<\/p>\r\n\r\n<p><script><\/script><\/p>","protected":false},"excerpt":{"rendered":"<p>To start, please log in to your Ubuntu instance. Next, it&#8217;s important to update the repository to ensure that we have the most recent and secure version. Once the repository is successfully updated, we can proceed. To start, please log in to your Ubuntu instance. Next, it&#8217;s important to update the repository to ensure that we have the most recent and secure version. Once the repository is successfully updated, we can proceed.<\/p>\n","protected":false},"author":1,"featured_media":5346,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[255],"tags":[],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"https:\/\/i0.wp.com\/natsav.com\/blog\/wp-content\/uploads\/2023\/10\/nginx.png?fit=798%2C478&ssl=1","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/posts\/5366"}],"collection":[{"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/comments?post=5366"}],"version-history":[{"count":3,"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/posts\/5366\/revisions"}],"predecessor-version":[{"id":5883,"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/posts\/5366\/revisions\/5883"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/media\/5346"}],"wp:attachment":[{"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/media?parent=5366"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/categories?post=5366"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/tags?post=5366"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}