{"id":15064694,"url":"https://github.com/sumanadithan/nginx","last_synced_at":"2026-01-24T18:03:11.646Z","repository":{"id":253629788,"uuid":"844055800","full_name":"SumanAdithan/nginx","owner":"SumanAdithan","description":"This repository contains Docker configurations for Nginx and Express servers, demonstrating web server setups, load balancing, and URL management.","archived":false,"fork":false,"pushed_at":"2024-08-29T16:40:18.000Z","size":3818,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-24T11:21:38.105Z","etag":null,"topics":["containerization","docker","express","load-balancing","nginx","url-rewriting","web-server"],"latest_commit_sha":null,"homepage":"","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SumanAdithan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-18T08:40:31.000Z","updated_at":"2024-12-14T05:59:16.000Z","dependencies_parsed_at":"2024-08-18T11:11:54.174Z","dependency_job_id":"be669553-d46f-4c71-a828-0c5e09493703","html_url":"https://github.com/SumanAdithan/nginx","commit_stats":null,"previous_names":["sumanadithan/nginx"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SumanAdithan%2Fnginx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SumanAdithan%2Fnginx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SumanAdithan%2Fnginx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SumanAdithan%2Fnginx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SumanAdithan","download_url":"https://codeload.github.com/SumanAdithan/nginx/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248217156,"owners_count":21066634,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["containerization","docker","express","load-balancing","nginx","url-rewriting","web-server"],"created_at":"2024-09-25T00:25:08.631Z","updated_at":"2026-01-24T18:03:11.575Z","avatar_url":"https://github.com/SumanAdithan.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Nginx Setup Guide\n\n## Installation\n\nRun the following commands to install Nginx:\n\n    sudo apt update\n    sudo apt install nginx\n\nit create nginx directory in: /etc/nginx\nVisit http://YOUR_IP or http://127.0.0.1 in your browser. You should see Welcome to nginx.\n\n## Location\n\n-   **Root Location for Default Page:**\n\n    -   Default location: /var/www/html\n\n    -   For multiple domains, use virtual hosts.\n\n-   **Create a Folder and HTML File:**\n    -   Create a directory: /var/www/sample\n    -   Add an HTML file to this directory.\n\n## Virtual Host Configuration\n\n1.  **Create a Virtual Host Configuration File:**\n\n    ```bash\n    sudo nano /etc/nginx/sites-available/sample\n    ```\n\n2.  **Add the Following Configuration:**\n\n        ```\n        server {\n            # Listen on port 81 for both IPv4 and IPv6 connections\n            listen 81;\n            listen [::]:81;\n\n            # Define the server name; replace 'YOUR_IP' with your server's IP address or domain name\n            server_name YOUR_IP;\n\n            # Set the root directory where the server will look for files\n            root /var/www/sample;\n\n            # Define the default index file\n            index index.html;\n\n            # Location block for handling requests to the root URL\n            location / {\n                # Try to serve the requested file or directory; if not found, return a 404 error\n                try_files $uri $uri/ =404;\n            }\n\n        }\n\n3.  **Add symbolic link:**\n    ```bash\n    sudo ln -s /etc/nginx/sites-available/sample /etc/nginx/sites-enabled/\n    ```\n\n## Test the Configuration\n\n1. **Restart or Reload Nginx:**\n\n    ```bash\n    sudo service nginx restart\n    ```\n\n    or\n\n    ```bash\n    sudo systemctl reload nginx\n    ```\n\n    or\n\n    ```bash\n    sudo systemctl restart nginx\n    ```\n\n2. **Open the URL:**\n   Visit http://YOUR_IP:81 or http://127.0.0.1:81 in your browser. You should see the content of index.html.\n\n## Test Nginx Configuration\n\nTo test your Nginx configuration for syntax errors, use:\n\n```\nsudo nginx -t\n```\n\n## Display the Effective Nginx Configuration\n\nTo display the complete and effective configuration as interpreted by Nginx, use:\n\n```\nsudo nginx -T\n```\n\n## Check Error Logs\n\nTo view error logs, use:\n\n    sudo tail -f /var/log/nginx/error.log\n\n## Nginx Terminology\n\n#### Directives\n\nNginx is configured using directives, which are key-value pairs that determine the behavior of the server. Directives can control various settings, such as the number of worker processes or the root directory for files.\n\nExample:\n\n```\nworker_processes 1;\n```\n\n#### Contexts\n\nContexts are blocks that group related directives together. They help organize the Nginx configuration and define the scope in which certain directives apply.\n\nExample:\n\n```\nevents {\n    worker_connections 1024;\n}\n```\n\n## Test Nginx Configuration\n\nTo test your Nginx configuration for syntax errors, use:\n\n```\nsudo nginx -t\n```\n\n## Display the Effective Nginx Configuration\n\nTo display the complete and effective configuration as interpreted by Nginx, use:\n\n```\nsudo nginx -T\n```\n\n## Location Context\n\nThe location context is used to define how specific requests should be handled within a server block. Different location blocks can be used to serve different parts of a website or apply specific configurations to certain paths.\n\nExample:\n\n```\nserver {\n    listen 81;\n    listen [::]:81;\n\n    server_name YOUR_IP;\n\n    root /var/www/oibsib;\n    index index.html;\n\n    # Task 1 - Standard root usage\n    location /task-1 {\n        try_files $uri $uri/ =404;\n    }\n\n    # Task 2 - Using alias to map task-2 to task-3 directory\n    location /task-2 {\n        alias /var/www/oibsib/task-3/;\n        try_files $uri $uri/ =404;\n    }\n\n    # Task 3 - Standard root usage with specific file handling\n    location /task-3 {\n        try_files /task-3/index.js /task-3/index.html =404;\n    }\n\n    # Catch-all location for root directory\n    location / {\n        try_files $uri $uri/ =404;\n    }\n}\n```\n\n## Redirects and Rewrites\n\nRedirects and rewrites are used in Nginx to alter the requested URL path, either by redirecting the client to a different URL or by internally rewriting the request to a different path.\n\nExample:\n\n```\nserver {\n    listen 81;\n    listen [::]:81;\n        Replace YOUR_IP with your server's IP address.\n\n    server_name YOUR_IP;\n\n    root /var/www/oibsib;\n    index index.html;\n\n    # Rewrite /number/... to /count/...\n    rewrite ^/number/(\\w+) /count/$1 last;\n\n    # Match /count/ followed by a single digit and use root for task-3\n    location ~* ^/count/[0-9]$ {\n        root /var/www/oibsib/task-3;\n        try_files $uri $uri/ /index.html =404;\n    }\n\n    # Redirect /abc to /task-1\n    location /abc {\n        return 307 /task-1;\n    }\n\n    # Catch-all location for root directory\n    location / {\n        try_files $uri $uri/ =404;\n    }\n}\n```\n\n## Load Balancing\n\nLoad balancing is a technique used to distribute incoming network traffic across multiple servers to ensure no single server is overwhelmed. Nginx supports several load balancing algorithms, and one of the most common is the round-robin algorithm.\n\n#### Round-Robin Algorithm\n\nThe round-robin algorithm distributes requests evenly across all servers in the upstream group. This is the default method for load balancing in Nginx.\n\nExample:\n\n```\nupstream backendserver {\n    server 127.0.0.1:1111;\n    server 127.0.0.1:2222;\n    server 127.0.0.1:3333;\n    server 127.0.0.1:4444;\n}\n\nserver {\n    listen 81;\n    listen [::]:81;\n\n    server_name YOUR_IP;\n\n    root /var/www/oibsib;\n    index index.html;\n\n    # Task 1 - Standard root usage\n    location /task-1 {\n        try_files $uri $uri/ =404;\n    }\n\n    # Task 2 - Using alias to map task-2 to task-3 directory\n    location /task-2 {\n        alias /var/www/oibsib/task-3/;\n        try_files $uri $uri/ =404;\n    }\n\n    # Task 3 - Standard root usage with specific file handling\n    location /task-3 {\n        try_files /task-3/index.js /task-3/index.html =404;\n    }\n\n    # Rewrite /number/... to /count/...\n    rewrite ^/number/(\\w+) /count/$1 last;\n\n    # Match /count/ followed by a single digit and use root for task-3\n    location ~* ^/count/[0-9]$ {\n        root /var/www/oibsib/task-3;\n        try_files $uri $uri/ /index.html =404;\n    }\n\n    # Redirect /abc to /task-1\n    location /abc {\n        return 307 /task-1;\n    }\n\n    # Proxy requests to the backend server group\n    location / {\n        proxy_pass http://backendserver/;\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsumanadithan%2Fnginx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsumanadithan%2Fnginx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsumanadithan%2Fnginx/lists"}