{"id":13928,"date":"2024-05-29T14:05:02","date_gmt":"2024-05-29T11:05:02","guid":{"rendered":"http:\/\/local.brightwhiz\/?p=13928"},"modified":"2024-05-29T14:05:04","modified_gmt":"2024-05-29T11:05:04","slug":"how-to-run-multiple-websites-using-nginx-webserver-on-ubuntu-24-04-noble-numbat","status":"publish","type":"post","link":"http:\/\/local.brightwhiz\/how-to-run-multiple-websites-using-nginx-webserver-on-ubuntu-24-04-noble-numbat\/","title":{"rendered":"How To Run Multiple Websites Using Nginx Webserver On Ubuntu 24.04 Noble Numbat"},"content":{"rendered":"\n

Running multiple websites on a single Nginx web server is a common requirement for web administrators. Nginx uses server blocks to manage multiple websites on the same server. This guide will show you how to set up multiple websites on an Nginx web<\/a> server running Ubuntu 24.04 Noble Numbat.<\/p>\n\n\n\n

Step 1: Update Your Package List<\/h2>\n\n\n\n

Before setting up your server, ensure that your package list is up to date. Open your terminal and run:<\/p>\n\n\n\n

$ sudo apt update<\/code><\/pre>\n\n\n\n

This command refreshes the package list to ensure you have the latest information on available packages.<\/p>\n\n\n\n

Step 2: Install Nginx<\/h2>\n\n\n\n

If you haven\u2019t installed Nginx<\/a> yet, you can do so by running:<\/p>\n\n\n\n

$ sudo apt install nginx<\/code><\/pre>\n\n\n\n

Step 3: Configure DNS for Each Domain<\/h2>\n\n\n\n

Make sure that each domain you plan to host is pointed to your server’s IP address. You can verify this with tools like dig<\/code>:<\/p>\n\n\n\n

$ dig yourdomain.com +short<\/code><\/pre>\n\n\n\n

Repeat this for each domain to ensure they all resolve to your server’s IP address.<\/p>\n\n\n\n

Step 4: Set Up Directory Structure<\/h2>\n\n\n\n

Create a directory for each website you plan to host. For example, to set up directories for example1.com<\/code> and example2.com<\/code>, run:<\/p>\n\n\n\n

$ sudo mkdir -p \/var\/www\/example1.com\/html\n$ sudo mkdir -p \/var\/www\/example2.com\/html<\/code><\/pre>\n\n\n\n

Set the correct permissions for these directories:<\/p>\n\n\n\n

$ sudo chown -R $USER:$USER \/var\/www\/example1.com\/html\n$ sudo chown -R $USER:$USER \/var\/www\/example2.com\/html\n$ sudo chmod -R 755 \/var\/www<\/code><\/pre>\n\n\n\n

Step 5: Create Sample Pages<\/h2>\n\n\n\n

Create a simple index.html file for each website to test the configuration. For example, for example1.com<\/code>:<\/p>\n\n\n\n

$ nano \/var\/www\/example1.com\/html\/index.html<\/code><\/pre>\n\n\n\n

Add the following content:<\/p>\n\n\n\n

<!DOCTYPE html>\n<html>\n<head>\n    <title>Welcome to example1.com!<\/title>\n<\/head>\n<body>\n    <h1>Success! The example1.com server block is working!<\/h1>\n<\/body>\n<\/html><\/code><\/pre>\n\n\n\n

Repeat the process for example2.com<\/code>:<\/p>\n\n\n\n

$ nano \/var\/www\/example2.com\/html\/index.html<\/code><\/pre>\n\n\n\n

Add the following content:<\/p>\n\n\n\n

<!DOCTYPE html>\n<html>\n<head>\n    <title>Welcome to example2.com!<\/title>\n<\/head>\n<body>\n    <h1>Success! The example2.com server block is working!<\/h1>\n<\/body>\n<\/html><\/code><\/pre>\n\n\n\n

Step 6: Configure Nginx Server Blocks<\/h2>\n\n\n\n

Create a server block configuration file for each website. For example1.com<\/code>:<\/p>\n\n\n\n

$ sudo nano \/etc\/nginx\/sites-available\/example1.com<\/code><\/pre>\n\n\n\n

Add the following configuration:<\/p>\n\n\n\n

server {\n    listen 80;\n    server_name example1.com www.example1.com;\n\n    root \/var\/www\/example1.com\/html;\n    index index.html index.htm;\n\n    location \/ {\n        try_files $uri $uri\/ =404;\n    }\n}<\/code><\/pre>\n\n\n\n

Repeat the process for example2.com<\/code>:<\/p>\n\n\n\n

$ sudo nano \/etc\/nginx\/sites-available\/example2.com<\/code><\/pre>\n\n\n\n

Add the following configuration:<\/p>\n\n\n\n

server {\n    listen 80;\n    server_name example2.com www.example2.com;\n\n    root \/var\/www\/example2.com\/html;\n    index index.html index.htm;\n\n    location \/ {\n        try_files $uri $uri\/ =404;\n    }\n}<\/code><\/pre>\n\n\n\n

Step 7: Enable the Server Blocks<\/h2>\n\n\n\n

Enable each server block by creating a symbolic link from the sites-available directory to the sites-enabled directory. For example1.com<\/code>:<\/p>\n\n\n\n

$ sudo ln -s \/etc\/nginx\/sites-available\/example1.com \/etc\/nginx\/sites-enabled\/<\/code><\/pre>\n\n\n\n

For example2.com<\/code>:<\/p>\n\n\n\n

$ sudo ln -s \/etc\/nginx\/sites-available\/example2.com \/etc\/nginx\/sites-enabled\/<\/code><\/pre>\n\n\n\n

Step 8: Test Nginx Configuration<\/h2>\n\n\n\n

Test the Nginx configuration for syntax errors:<\/p>\n\n\n\n

$ sudo nginx -t<\/code><\/pre>\n\n\n\n

If the output indicates that the syntax is OK, reload Nginx to apply the changes:<\/p>\n\n\n\n

$ sudo systemctl reload nginx<\/code><\/pre>\n\n\n\n

Step 9: Verify the Setup<\/h2>\n\n\n\n

Open your web browser and navigate to http:\/\/example1.com<\/code> and http:\/\/example2.com<\/code>. You should see the respective sample pages for each domain, confirming that both sites are being served correctly by Nginx.<\/p>\n\n\n\n

Step 10: Secure Your Websites with SSL (Optional)<\/h2>\n\n\n\n

For better security, you should secure your websites with SSL certificates. You can use Certbot to obtain free SSL certificates from Let’s Encrypt. Install Certbot and the Nginx plugin:<\/p>\n\n\n\n

$ sudo apt install certbot python3-certbot-nginx<\/code><\/pre>\n\n\n\n

Obtain and install certificates for each domain:<\/p>\n\n\n\n

$ sudo certbot --nginx -d example1.com -d www.example1.com\n$ sudo certbot --nginx -d example2.com -d www.example2.com<\/code><\/pre>\n\n\n\n

Certbot will automatically configure Nginx to use the SSL certificates and set up redirection from HTTP to HTTPS.<\/p>\n\n\n\n

Conclusion<\/h2>\n\n\n\n

You have successfully configured Nginx to host multiple websites on a single server running Ubuntu<\/a> 24.04 Noble Numbat. By following these steps, you can manage multiple domains efficiently and ensure your sites are secure and performant.<\/p>\n","protected":false},"excerpt":{"rendered":"

Running multiple websites on a single Nginx web server is a common requirement for web administrators. Nginx uses server blocks to manage multiple websites on the same server. This guide…<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,23,9,28,16,18],"tags":[350,354,400,424,433,449,531,591,598,635,636,638],"yoast_head":"\nHow To Run Multiple Websites Using Nginx On Ubuntu 24.04<\/title>\n<meta name=\"description\" content=\"This guide will show you how to set up multiple websites on an Nginx web server running Ubuntu 24.04 Noble Numbat\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/local.brightwhiz\/how-to-run-multiple-websites-using-nginx-webserver-on-ubuntu-24-04-noble-numbat\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How To Run Multiple Websites Using Nginx On Ubuntu 24.04\" \/>\n<meta property=\"og:description\" content=\"This guide will show you how to set up multiple websites on an Nginx web server running Ubuntu 24.04 Noble Numbat\" \/>\n<meta property=\"og:url\" content=\"http:\/\/local.brightwhiz\/how-to-run-multiple-websites-using-nginx-webserver-on-ubuntu-24-04-noble-numbat\/\" \/>\n<meta property=\"og:site_name\" content=\"Brightwhiz.com\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/brightwhiz\/\" \/>\n<meta property=\"article:published_time\" content=\"2024-05-29T11:05:02+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-05-29T11:05:04+00:00\" \/>\n<meta name=\"author\" content=\"Michael Bright\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@brightwhizmag\" \/>\n<meta name=\"twitter:site\" content=\"@brightwhizmag\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Michael Bright\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"http:\/\/local.brightwhiz\/how-to-run-multiple-websites-using-nginx-webserver-on-ubuntu-24-04-noble-numbat\/#article\",\"isPartOf\":{\"@id\":\"http:\/\/local.brightwhiz\/how-to-run-multiple-websites-using-nginx-webserver-on-ubuntu-24-04-noble-numbat\/\"},\"author\":{\"name\":\"Michael Bright\",\"@id\":\"http:\/\/local.brightwhiz\/#\/schema\/person\/81f0f3126f13834ae2e7f381b3028e32\"},\"headline\":\"How To Run Multiple Websites Using Nginx Webserver On Ubuntu 24.04 Noble Numbat\",\"datePublished\":\"2024-05-29T11:05:02+00:00\",\"dateModified\":\"2024-05-29T11:05:04+00:00\",\"mainEntityOfPage\":{\"@id\":\"http:\/\/local.brightwhiz\/how-to-run-multiple-websites-using-nginx-webserver-on-ubuntu-24-04-noble-numbat\/\"},\"wordCount\":432,\"publisher\":{\"@id\":\"http:\/\/local.brightwhiz\/#organization\"},\"keywords\":[\"Libraries\",\"Linux\",\"Nginx\",\"Open Source\",\"Optimization\",\"Performance\",\"Server\",\"Tools\",\"Ubuntu\",\"Web\",\"Web Applications\",\"Web Development\"],\"articleSection\":[\"Articles\",\"Guides\",\"How To\",\"Software\",\"Technology\",\"Tools\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"http:\/\/local.brightwhiz\/how-to-run-multiple-websites-using-nginx-webserver-on-ubuntu-24-04-noble-numbat\/\",\"url\":\"http:\/\/local.brightwhiz\/how-to-run-multiple-websites-using-nginx-webserver-on-ubuntu-24-04-noble-numbat\/\",\"name\":\"How To Run Multiple Websites Using Nginx On Ubuntu 24.04\",\"isPartOf\":{\"@id\":\"http:\/\/local.brightwhiz\/#website\"},\"datePublished\":\"2024-05-29T11:05:02+00:00\",\"dateModified\":\"2024-05-29T11:05:04+00:00\",\"description\":\"This guide will show you how to set up multiple websites on an Nginx web server running Ubuntu 24.04 Noble Numbat\",\"breadcrumb\":{\"@id\":\"http:\/\/local.brightwhiz\/how-to-run-multiple-websites-using-nginx-webserver-on-ubuntu-24-04-noble-numbat\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/local.brightwhiz\/how-to-run-multiple-websites-using-nginx-webserver-on-ubuntu-24-04-noble-numbat\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/local.brightwhiz\/how-to-run-multiple-websites-using-nginx-webserver-on-ubuntu-24-04-noble-numbat\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/local.brightwhiz\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How To Run Multiple Websites Using Nginx Webserver On Ubuntu 24.04 Noble Numbat\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/local.brightwhiz\/#website\",\"url\":\"http:\/\/local.brightwhiz\/\",\"name\":\"Brightwhiz.com\",\"description\":\"Best Tech guides, Tutorials, and News\",\"publisher\":{\"@id\":\"http:\/\/local.brightwhiz\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/local.brightwhiz\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"http:\/\/local.brightwhiz\/#organization\",\"name\":\"Brightwhiz\",\"url\":\"http:\/\/local.brightwhiz\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/local.brightwhiz\/#\/schema\/logo\/image\/\",\"url\":\"http:\/\/local.brightwhiz\/wp-content\/uploads\/2021\/11\/brightwhiz-com-logo-orange.png\",\"contentUrl\":\"http:\/\/local.brightwhiz\/wp-content\/uploads\/2021\/11\/brightwhiz-com-logo-orange.png\",\"width\":706,\"height\":135,\"caption\":\"Brightwhiz\"},\"image\":{\"@id\":\"http:\/\/local.brightwhiz\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/brightwhiz\/\",\"https:\/\/x.com\/brightwhizmag\",\"https:\/\/instagram.com\/bright_whiz\/\",\"https:\/\/www.pinterest.com\/sobbayi\/\",\"https:\/\/www.youtube.com\/channel\/UC6sCdP_d_RiTIM7ErFT-PSQ\"]},{\"@type\":\"Person\",\"@id\":\"http:\/\/local.brightwhiz\/#\/schema\/person\/81f0f3126f13834ae2e7f381b3028e32\",\"name\":\"Michael Bright\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/local.brightwhiz\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/1.gravatar.com\/avatar\/da90485875ff0aafa38fdd494abe87d1?s=96&d=mm&r=g\",\"contentUrl\":\"http:\/\/1.gravatar.com\/avatar\/da90485875ff0aafa38fdd494abe87d1?s=96&d=mm&r=g\",\"caption\":\"Michael Bright\"},\"sameAs\":[\"https:\/\/sobbayi.com\"],\"url\":\"http:\/\/local.brightwhiz\/author\/sobbayiadmin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How To Run Multiple Websites Using Nginx On Ubuntu 24.04","description":"This guide will show you how to set up multiple websites on an Nginx web server running Ubuntu 24.04 Noble Numbat","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/local.brightwhiz\/how-to-run-multiple-websites-using-nginx-webserver-on-ubuntu-24-04-noble-numbat\/","og_locale":"en_US","og_type":"article","og_title":"How To Run Multiple Websites Using Nginx On Ubuntu 24.04","og_description":"This guide will show you how to set up multiple websites on an Nginx web server running Ubuntu 24.04 Noble Numbat","og_url":"http:\/\/local.brightwhiz\/how-to-run-multiple-websites-using-nginx-webserver-on-ubuntu-24-04-noble-numbat\/","og_site_name":"Brightwhiz.com","article_publisher":"https:\/\/www.facebook.com\/brightwhiz\/","article_published_time":"2024-05-29T11:05:02+00:00","article_modified_time":"2024-05-29T11:05:04+00:00","author":"Michael Bright","twitter_card":"summary_large_image","twitter_creator":"@brightwhizmag","twitter_site":"@brightwhizmag","twitter_misc":{"Written by":"Michael Bright","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"http:\/\/local.brightwhiz\/how-to-run-multiple-websites-using-nginx-webserver-on-ubuntu-24-04-noble-numbat\/#article","isPartOf":{"@id":"http:\/\/local.brightwhiz\/how-to-run-multiple-websites-using-nginx-webserver-on-ubuntu-24-04-noble-numbat\/"},"author":{"name":"Michael Bright","@id":"http:\/\/local.brightwhiz\/#\/schema\/person\/81f0f3126f13834ae2e7f381b3028e32"},"headline":"How To Run Multiple Websites Using Nginx Webserver On Ubuntu 24.04 Noble Numbat","datePublished":"2024-05-29T11:05:02+00:00","dateModified":"2024-05-29T11:05:04+00:00","mainEntityOfPage":{"@id":"http:\/\/local.brightwhiz\/how-to-run-multiple-websites-using-nginx-webserver-on-ubuntu-24-04-noble-numbat\/"},"wordCount":432,"publisher":{"@id":"http:\/\/local.brightwhiz\/#organization"},"keywords":["Libraries","Linux","Nginx","Open Source","Optimization","Performance","Server","Tools","Ubuntu","Web","Web Applications","Web Development"],"articleSection":["Articles","Guides","How To","Software","Technology","Tools"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"http:\/\/local.brightwhiz\/how-to-run-multiple-websites-using-nginx-webserver-on-ubuntu-24-04-noble-numbat\/","url":"http:\/\/local.brightwhiz\/how-to-run-multiple-websites-using-nginx-webserver-on-ubuntu-24-04-noble-numbat\/","name":"How To Run Multiple Websites Using Nginx On Ubuntu 24.04","isPartOf":{"@id":"http:\/\/local.brightwhiz\/#website"},"datePublished":"2024-05-29T11:05:02+00:00","dateModified":"2024-05-29T11:05:04+00:00","description":"This guide will show you how to set up multiple websites on an Nginx web server running Ubuntu 24.04 Noble Numbat","breadcrumb":{"@id":"http:\/\/local.brightwhiz\/how-to-run-multiple-websites-using-nginx-webserver-on-ubuntu-24-04-noble-numbat\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/local.brightwhiz\/how-to-run-multiple-websites-using-nginx-webserver-on-ubuntu-24-04-noble-numbat\/"]}]},{"@type":"BreadcrumbList","@id":"http:\/\/local.brightwhiz\/how-to-run-multiple-websites-using-nginx-webserver-on-ubuntu-24-04-noble-numbat\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/local.brightwhiz\/"},{"@type":"ListItem","position":2,"name":"How To Run Multiple Websites Using Nginx Webserver On Ubuntu 24.04 Noble Numbat"}]},{"@type":"WebSite","@id":"http:\/\/local.brightwhiz\/#website","url":"http:\/\/local.brightwhiz\/","name":"Brightwhiz.com","description":"Best Tech guides, Tutorials, and News","publisher":{"@id":"http:\/\/local.brightwhiz\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/local.brightwhiz\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"http:\/\/local.brightwhiz\/#organization","name":"Brightwhiz","url":"http:\/\/local.brightwhiz\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/local.brightwhiz\/#\/schema\/logo\/image\/","url":"http:\/\/local.brightwhiz\/wp-content\/uploads\/2021\/11\/brightwhiz-com-logo-orange.png","contentUrl":"http:\/\/local.brightwhiz\/wp-content\/uploads\/2021\/11\/brightwhiz-com-logo-orange.png","width":706,"height":135,"caption":"Brightwhiz"},"image":{"@id":"http:\/\/local.brightwhiz\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/brightwhiz\/","https:\/\/x.com\/brightwhizmag","https:\/\/instagram.com\/bright_whiz\/","https:\/\/www.pinterest.com\/sobbayi\/","https:\/\/www.youtube.com\/channel\/UC6sCdP_d_RiTIM7ErFT-PSQ"]},{"@type":"Person","@id":"http:\/\/local.brightwhiz\/#\/schema\/person\/81f0f3126f13834ae2e7f381b3028e32","name":"Michael Bright","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/local.brightwhiz\/#\/schema\/person\/image\/","url":"http:\/\/1.gravatar.com\/avatar\/da90485875ff0aafa38fdd494abe87d1?s=96&d=mm&r=g","contentUrl":"http:\/\/1.gravatar.com\/avatar\/da90485875ff0aafa38fdd494abe87d1?s=96&d=mm&r=g","caption":"Michael Bright"},"sameAs":["https:\/\/sobbayi.com"],"url":"http:\/\/local.brightwhiz\/author\/sobbayiadmin\/"}]}},"_links":{"self":[{"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/posts\/13928"}],"collection":[{"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/comments?post=13928"}],"version-history":[{"count":2,"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/posts\/13928\/revisions"}],"predecessor-version":[{"id":13952,"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/posts\/13928\/revisions\/13952"}],"wp:attachment":[{"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/media?parent=13928"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/categories?post=13928"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/tags?post=13928"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}