{"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 Before setting up your server, ensure that your package list is up to date. Open your terminal and run:<\/p>\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 If you haven\u2019t installed Nginx<\/a> yet, you can do so by running:<\/p>\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 Repeat this for each domain to ensure they all resolve to your server’s IP address.<\/p>\n\n\n\n Create a directory for each website you plan to host. For example, to set up directories for Set the correct permissions for these directories:<\/p>\n\n\n\n Create a simple index.html file for each website to test the configuration. For example, for Add the following content:<\/p>\n\n\n\n Repeat the process for Add the following content:<\/p>\n\n\n\n Create a server block configuration file for each website. For Add the following configuration:<\/p>\n\n\n\n Repeat the process for Add the following configuration:<\/p>\n\n\n\n Enable each server block by creating a symbolic link from the sites-available directory to the sites-enabled directory. For For Test the Nginx configuration for syntax errors:<\/p>\n\n\n\n If the output indicates that the syntax is OK, reload Nginx to apply the changes:<\/p>\n\n\n\n Open your web browser and navigate to 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 Obtain and install certificates for each domain:<\/p>\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 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":"\nStep 1: Update Your Package List<\/h2>\n\n\n\n
$ sudo apt update<\/code><\/pre>\n\n\n\n
Step 2: Install Nginx<\/h2>\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
dig<\/code>:<\/p>\n\n\n\n
$ dig yourdomain.com +short<\/code><\/pre>\n\n\n\n
Step 4: Set Up Directory Structure<\/h2>\n\n\n\n
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
$ 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
example1.com<\/code>:<\/p>\n\n\n\n
$ nano \/var\/www\/example1.com\/html\/index.html<\/code><\/pre>\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
example2.com<\/code>:<\/p>\n\n\n\n
$ nano \/var\/www\/example2.com\/html\/index.html<\/code><\/pre>\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
example1.com<\/code>:<\/p>\n\n\n\n
$ sudo nano \/etc\/nginx\/sites-available\/example1.com<\/code><\/pre>\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
example2.com<\/code>:<\/p>\n\n\n\n
$ sudo nano \/etc\/nginx\/sites-available\/example2.com<\/code><\/pre>\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
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
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
$ sudo nginx -t<\/code><\/pre>\n\n\n\n
$ sudo systemctl reload nginx<\/code><\/pre>\n\n\n\n
Step 9: Verify the Setup<\/h2>\n\n\n\n
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
$ sudo apt install certbot python3-certbot-nginx<\/code><\/pre>\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
Conclusion<\/h2>\n\n\n\n