Here are a few common Nginx syntax examples


1. Basic Server Block:

```nginx
server {
    listen 80;
    server_name example.com;
    root /var/www/html;
    index index.html;
}
```

2. Location Block:

```nginx
server {
    listen 80;
    server_name example.com;

    location /images/ {
        alias /var/www/images/;
    }

    location / {
        proxy_pass http://backend_server;
    }
}
```

3. Reverse Proxy:

```nginx
server {
    listen 80;
    server_name app.example.com;

    location / {
        proxy_pass http://backend_server;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
}
```

4. SSL Configuration:

```nginx
server {
    listen 443;
    server_name secure.example.com;

    ssl on;
    ssl_certificate /etc/nginx/ssl/server.crt;
    ssl_certificate_key /etc/nginx/ssl/server.key;

    location / {
        proxy_pass http://backend_server;
    }
}
```

5. Load Balancing:

```nginx
upstream backend_servers {
    server backend1.example.com;
    server backend2.example.com;
}

server {
    listen 80;
    server_name app.example.com;

    location / {
        proxy_pass http://backend_servers;
    }
}
```

Remember to replace placeholders like `example.com`, `backend_server`, and file paths with your actual values. Also, keep in mind that Nginx configuration can get complex based on your requirements. Always test and verify your configuration after making changes.


6. Basic Authentication:

```nginx
server {
    listen 80;
    server_name secured.example.com;

    location / {
        auth_basic "Restricted Content";
        auth_basic_user_file /etc/nginx/.htpasswd;

        proxy_pass http://backend_server;
    }
}
```

7. Caching:

```nginx
server {
    listen 80;
    server_name caching.example.com;

    location / {
        proxy_pass http://backend_server;
        proxy_cache my_cache;
        proxy_cache_valid 200 302 10m;
        proxy_cache_valid 404 1m;
    }
}
```

8. Gzip Compression:

```nginx
server {
    listen 80;
    server_name example.com;

    gzip on;
    gzip_types text/plain text/css application/json;

    location / {
        root /var/www/html;
        index index.html;
    }
}
```

9. Custom Error Pages:

```nginx
server {
    listen 80;
    server_name example.com;

    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;

    location = /50x.html {
        root /usr/share/nginx/html;
    }
}
```

10. Rate Limiting:

```nginx
server {
    listen 80;
    server_name api.example.com;

    location / {
        limit_req zone=my_zone burst=5 nodelay;
        proxy_pass http://backend_server;
    }
}
```

These examples cover a range of Nginx features and configurations. Always make sure to review and adapt them according to your specific needs and setup. Nginx documentation is a valuable resource for more in-depth understanding and customization.


11. HTTP/2 and SSL:

```nginx
server {
    listen 443 ssl http2;
    server_name secure.example.com;

    ssl_certificate /etc/nginx/ssl/server.crt;
    ssl_certificate_key /etc/nginx/ssl/server.key;

    location / {
        proxy_pass http://backend_server;
    }
}
```

12. WebSockets:

```nginx
server {
    listen 80;
    server_name chat.example.com;

    location /ws {
        proxy_pass http://websocket_backend;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}
```

13. IP Restriction:

```nginx
server {
    listen 80;
    server_name restricted.example.com;

    allow 192.168.1.0/24;
    deny all;

    location / {
        proxy_pass http://backend_server;
    }
}
```

14. Server Blocks (Virtual Hosts):

```nginx
server {
    listen 80;
    server_name site1.example.com;

    location / {
        root /var/www/site1;
        index index.html;
    }
}

server {
    listen 80;
    server_name site2.example.com;

    location / {
        root /var/www/site2;
        index index.html;
    }
}
```

15. Custom Logging:

```nginx
http {
    log_format custom_log '$remote_addr - $remote_user [$time_local] '
                        '"$request" $status $body_bytes_sent '
                        '"$http_referer" "$http_user_agent"';

    access_log /var/log/nginx/access.log custom_log;
}
```

These examples should help you further understand and configure Nginx for various scenarios. Remember to adapt them to your specific use cases and always test your configuration changes.


16. Server Name Aliasing:

```nginx
server {
    listen 80;
    server_name www.example.com;

    location / {
        root /var/www/html;
        index index.html;
    }
}

server {
    listen 80;
    server_name example.com;

    location / {
        return 301 http://www.example.com$request_uri;
    }
}
```

17. Proxy Buffering:

```nginx
server {
    listen 80;
    server_name proxy.example.com;

    location / {
        proxy_pass http://backend_server;
        proxy_buffering on;
        proxy_buffers 8 16k;
        proxy_buffer_size 32k;
    }
}
```

18. Map Directive for Conditional Configuration:

```nginx
map $http_user_agent $mobile {
    default         0;
    ~*mobile|Android|iPhone  1;
}

server {
    listen 80;
    server_name example.com;

    if ($mobile) {
        rewrite ^ /mobile$request_uri;
    }

    location /mobile {
        root /var/www/mobile;
        index index.html;
    }

    location / {
        root /var/www/desktop;
        index index.html;
    }
}
```

19. HTTPS Redirect:

```nginx
server {
    listen 80;
    server_name example.com;
    
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl;
    server_name example.com;

    ssl_certificate /etc/nginx/ssl/server.crt;
    ssl_certificate_key /etc/nginx/ssl/server.key;

    location / {
        root /var/www/html;
        index index.html;
    }
}
```

20. Custom Headers:

```nginx
server {
    listen 80;
    server_name api.example.com;

    location / {
        proxy_pass http://backend_server;
        proxy_set_header X-Custom-Header "Custom Value";
    }
}
```

Feel free to adapt and modify these examples according to your needs. Nginx's flexibility allows you to configure it for a wide variety of scenarios and requirements. As always, ensure that you thoroughly test your configurations after making changes.


21. Multiple Location Blocks:

```nginx
server {
    listen 80;
    server_name example.com;

    location / {
        root /var/www/html;
        index index.html;
    }

    location /images/ {
        alias /var/www/images/;
    }

    location /api/ {
        proxy_pass http://api_backend;
    }
}
```

22. Blocking Specific User Agents:

```nginx
server {
    listen 80;
    server_name example.com;

    if ($http_user_agent ~* (bot|spider)) {
        return 403;
    }

    location / {
        root /var/www/html;
        index index.html;
    }
}
```

23. Custom Error Pages for Different Status Codes:

```nginx
server {
    listen 80;
    server_name example.com;

    error_page 404 /404.html;
    error_page 500 /500.html;

    location = /404.html {
        root /var/www/errors;
    }

    location = /500.html {
        root /var/www/errors;
    }
}
```

24. Limiting Connections per IP:

```nginx
server {
    listen 80;
    server_name example.com;

    limit_conn_zone $binary_remote_addr zone=conn_limit_per_ip:10m;

    location / {
        limit_conn conn_limit_per_ip 10;
        root /var/www/html;
        index index.html;
    }
}
```

25. Maintenance Page:

```nginx
server {
    listen 80;
    server_name example.com;

    location / {
        root /var/www/maintenance;
        index index.html;
    }

    location /assets/ {
        root /var/www/maintenance/assets;
    }
}
```

These additional examples cover more scenarios and configurations that you might find useful when setting up your Nginx server. Remember to adapt them to your specific requirements and thoroughly test your configuration changes.


26. Rate Limiting with Burst and Delay:

```nginx
http {
    limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s;

    server {
        listen 80;
        server_name example.com;

        location /api/ {
            limit_req zone=one burst=5 nodelay;
            proxy_pass http://api_backend;
        }
    }
}
```

27. Using Include Directive for Modular Configuration:

Create a separate file named `my_config.conf`:

```nginx
# my_config.conf
location /special/ {
    root /var/www/special;
    index index.html;
}
```

Include the above configuration in your main Nginx configuration file:

```nginx
http {
    include /etc/nginx/conf.d/my_config.conf;

    server {
        listen 80;
        server_name example.com;

        location / {
            root /var/www/html;
            index index.html;
        }
    }
}
```

28. Custom Server Tokens for Security:

```nginx
http {
    server_tokens off;

    server {
        listen 80;
        server_name example.com;

        location / {
            root /var/www/html;
            index index.html;
        }
    }
}
```

29. Secure Headers for Enhanced Security:

```nginx
server {
    listen 80;
    server_name secure.example.com;

    add_header X-Content-Type-Options nosniff;
    add_header X-Frame-Options DENY;
    add_header X-XSS-Protection "1; mode=block";

    location / {
        root /var/www/secure;
        index index.html;
    }
}
```

30. HTTPS Configuration with HTTP/2 and OCSP Stapling:

```nginx
server {
    listen 443 ssl http2;
    server_name secure.example.com;

    ssl_certificate /etc/nginx/ssl/server.crt;
    ssl_certificate_key /etc/nginx/ssl/server.key;
    ssl_trusted_certificate /etc/nginx/ssl/trusted.crt;

    ssl_stapling on;
    ssl_stapling_verify on;

    location / {
        root /var/www/secure;
        index index.html;
    }
}
```

These additional examples cover more advanced scenarios and configurations you might encounter while working with Nginx. As always, adapt them to your needs and thoroughly test your setup before deploying to a production environment.


31. Custom Rewrite Rules:

```nginx
server {
    listen 80;
    server_name example.com;

    location /old-page {
        rewrite ^/old-page$ /new-page permanent;
    }

    location / {
        root /var/www/html;
        index index.html;
    }
}
```

32. Load Balancing with Session Persistence:

```nginx
upstream backend_servers {
    server backend1.example.com;
    server backend2.example.com;
    sticky name=backend_servers_sticky hash=sha1;
}

server {
    listen 80;
    server_name app.example.com;

    location / {
        proxy_pass http://backend_servers;
    }
}
```

33. Redirecting Specific URLs:

```nginx
server {
    listen 80;
    server_name example.com;

    location /old-url {
        rewrite ^/old-url$ http://example.com/new-url permanent;
    }

    location / {
        root /var/www/html;
        index index.html;
    }
}
```

34. Hiding Certain File Types:

```nginx
server {
    listen 80;
    server_name example.com;

    location ~* \.(log|ini)$ {
        deny all;
    }

    location / {
        root /var/www/html;
        index index.html;
    }
}
```

35. Proxying to Different Backend Based on URL Path:

```nginx
server {
    listen 80;
    server_name example.com;

    location /app1/ {
        proxy_pass http://backend_server1;
    }

    location /app2/ {
        proxy_pass http://backend_server2;
    }

    location / {
        root /var/www/html;
        index index.html;
    }
}
```

These final examples cover more advanced configurations and use cases when working with Nginx. Remember to always tailor the configurations to your specific needs and thoroughly test them to ensure proper functionality.


36. Dynamic Content Compression:

```nginx
server {
    listen 80;
    server_name example.com;

    gzip on;
    gzip_types application/javascript text/css;

    location / {
        root /var/www/html;
        index index.html;
    }
}
```

37. Blocking Access by IP Range:

```nginx
server {
    listen 80;
    server_name example.com;

    location / {
        deny 192.168.1.0/24;
        allow all;
        root /var/www/html;
        index index.html;
    }
}
```

38. Using try_files for Clean URLs:

```nginx
server {
    listen 80;
    server_name example.com;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }
}
```

39. Restricting Access by Referrer:

```nginx
server {
    listen 80;
    server_name example.com;

    valid_referers none blocked example.com;

    if ($invalid_referer) {
        return 403;
    }

    location / {
        root /var/www/html;
        index index.html;
    }
}
```

40. Customizing Connection Timeouts:

```nginx
http {
    server {
        listen 80;
        server_name example.com;

        client_body_timeout 10s;
        client_header_timeout 10s;
        keepalive_timeout 15s;
        send_timeout 10s;

        location / {
            root /var/www/html;
            index index.html;
        }
    }
}
```

These examples cover a wide range of Nginx configurations and scenarios. As you integrate them into your setup, remember to adapt and test the configurations based on your specific environment and requirements.


41. Using Geo IP Module for IP-based Blocking:

```nginx
http {
    geo $blocked_country {
        default no;
        include /etc/nginx/block_countries.conf;
    }

    server {
        listen 80;
        server_name example.com;

        if ($blocked_country) {
            return 403;
        }

        location / {
            root /var/www/html;
            index index.html;
        }
    }
}
```

42. Customizing Response Headers:

```nginx
server {
    listen 80;
    server_name example.com;

    add_header X-Custom-Header "Hello, World!";
    add_header X-Frame-Options "SAMEORIGIN";

    location / {
        root /var/www/html;
        index index.html;
    }
}
```

43. Setting Up Nginx as a Reverse Proxy for Node.js:

```nginx
server {
    listen 80;
    server_name nodeapp.example.com;

    location / {
        proxy_pass http://127.0.0.1:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}
```

44. Using Regular Expressions in Location Blocks:

```nginx
server {
    listen 80;
    server_name example.com;

    location ~ ^/users/(\d+)/profile$ {
        rewrite ^ /profile?id=$1 last;
    }

    location / {
        root /var/www/html;
        index index.html;
    }
}
```

45. Restricting Access by HTTP Method:

```nginx
server {
    listen 80;
    server_name example.com;

    location /restricted {
        limit_except GET POST {
            deny all;
        }

        root /var/www/html;
        index index.html;
    }

    location / {
        root /var/www/html;
        index index.html;
    }
}
```

Feel free to adapt these examples to your specific needs and configurations. Nginx's flexibility allows you to create sophisticated setups for various scenarios. Always test thoroughly to ensure your configurations work as intended.


46. Using SSI (Server Side Includes):

```nginx
server {
    listen 80;
    server_name example.com;

    location / {
        root /var/www/html;
        index index.html;
        ssi on;
    }
}
```

47. Configuring FastCGI Caching:

```nginx
http {
    fastcgi_cache_path /var/cache/nginx levels=1:2 keys_zone=my_cache:10m;

    server {
        listen 80;
        server_name example.com;

        location ~ \.php$ {
            fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
            fastcgi_cache my_cache;
            fastcgi_cache_valid 200 10m;
        }

        location / {
            root /var/www/html;
            index index.html;
        }
    }
}
```

48. Using SSL Stapling for OCSP Validation:

```nginx
server {
    listen 443 ssl;
    server_name secure.example.com;

    ssl_certificate /etc/nginx/ssl/server.crt;
    ssl_certificate_key /etc/nginx/ssl/server.key;
    ssl_stapling on;
    ssl_stapling_verify on;

    location / {
        root /var/www/secure;
        index index.html;
    }
}
```

49. Creating Custom Response Pages:

```nginx
server {
    listen 80;
    server_name example.com;

    error_page 404 /404.html;
    error_page 500 /500.html;

    location = /404.html {
        root /var/www/errors;
    }

    location = /500.html {
        root /var/www/errors;
    }

    location / {
        root /var/www/html;
        index index.html;
    }
}
```

50. Enabling HTTP/2 Server Push:

```nginx
server {
    listen 80;
    server_name example.com;

    location / {
        root /var/www/html;
        index index.html;
        http2_push /css/styles.css;
        http2_push /js/main.js;
    }
}
```

Feel free to incorporate these examples into your Nginx setup according to your specific requirements. Nginx provides a wide array of features to help you build performant and secure web servers. Always test configurations before deploying them to a production environment.


51. Load Balancing with Weighted Servers:

```nginx
upstream backend_servers {
    server backend1.example.com weight=3;
    server backend2.example.com;
    server backend3.example.com weight=2;
}

server {
    listen 80;
    server_name app.example.com;

    location / {
        proxy_pass http://backend_servers;
    }
}
```

52. Rate Limiting with Different Limits for Different Locations:

```nginx
http {
    limit_req_zone $binary_remote_addr zone=api_zone:10m rate=10r/s;

    server {
        listen 80;
        server_name example.com;

        location /public {
            root /var/www/public;
            index index.html;
        }

        location /api {
            limit_req zone=api_zone burst=20 nodelay;
            proxy_pass http://backend_api;
        }
    }
}
```

53. Using the Map Module for Redirects:

```nginx
http {
    map $arg_oldpage $newpage {
        default /;
        about /about-us;
        contact /contact-us;
    }

    server {
        listen 80;
        server_name example.com;

        location / {
            rewrite ^ $newpage? permanent;
        }
    }
}
```

54. Handling Large File Uploads:

```nginx
http {
    client_max_body_size 10M;

    server {
        listen 80;
        server_name upload.example.com;

        location / {
            client_body_temp_path /var/www/uploads;
            client_body_in_file_only on;
            client_body_buffer_size 128K;
            proxy_pass http://backend_server;
        }
    }
}
```

55. Using the If Directive Carefully:

```nginx
server {
    listen 80;
    server_name example.com;

    if ($http_user_agent ~* MSIE) {
        rewrite ^ /legacy.html last;
    }

    location / {
        root /var/www/html;
        index index.html;
    }
}
```

These additional examples should provide further insights into the versatility of Nginx configuration. Always ensure to adjust and test the configurations for your specific use cases and requirements.


56. Using SSL Preloading for HSTS:

```nginx
server {
    listen 443 ssl;
    server_name secure.example.com;

    ssl_certificate /etc/nginx/ssl/server.crt;
    ssl_certificate_key /etc/nginx/ssl/server.key;
    
    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;

    location / {
        root /var/www/secure;
        index index.html;
    }
}
```

57. Configuring Nginx as a WebSocket Proxy:

```nginx
server {
    listen 80;
    server_name socket.example.com;

    location / {
        proxy_pass http://backend_server;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}
```

58. Using Error Codes to Redirect:

```nginx
server {
    listen 80;
    server_name example.com;

    error_page 404 =301 http://example.com/new-page;

    location / {
        root /var/www/html;
        index index.html;
    }
}
```

59. Removing Server Tokens and Version Information:

```nginx
http {
    server_tokens off;

    server {
        listen 80;
        server_name example.com;

        location / {
            root /var/www/html;
            index index.html;
        }
    }
}
```

60. Customizing Proxy Headers:

```nginx
server {
    listen 80;
    server_name example.com;

    location / {
        proxy_pass http://backend_server;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Real-IP $remote_addr;
    }
}
```

Feel free to incorporate these advanced examples into your Nginx configuration as needed. Nginx's flexibility enables you to tailor your setup to various scenarios and requirements. Always test and verify your configurations before deploying them to production.


61. Restricting Access to Specific IP Addresses:

```nginx
server {
    listen 80;
    server_name example.com;

    location / {
        allow 192.168.1.0/24;
        deny all;
        root /var/www/html;
        index index.html;
    }
}
```

62. Limiting Concurrent Connections for a Location:

```nginx
server {
    listen 80;
    server_name example.com;

    location /restricted {
        limit_conn conn_limit_per_ip 1;
        root /var/www/restricted;
        index index.html;
    }

    location / {
        root /var/www/html;
        index index.html;
    }
}
```

63. Using the Split Clients Module:

```nginx
http {
    split_clients "${remote_addr}AAA" $variant {
        10%    .A;
        90%    .B;
    }

    server {
        listen 80;
        server_name example.com;

        if ($variant = ".A") {
            root /var/www/variantA;
        }

        if ($variant = ".B") {
            root /var/www/variantB;
        }
    }
}
```

64. Adding Cache-Control Headers:

```nginx
server {
    listen 80;
    server_name example.com;

    location ~* \.(jpg|jpeg|png|gif|ico)$ {
        expires 1y;
        add_header Cache-Control "public, max-age=31536000";
    }

    location / {
        root /var/www/html;
        index index.html;
    }
}
```

65. Handling Large Numbers of Concurrent Connections:

```nginx
events {
    worker_connections 1024;
}

http {
    server {
        listen 80;
        server_name example.com;

        location / {
            root /var/www/html;
            index index.html;
        }
    }
}
```

Feel free to use these advanced examples as a reference to further customize and optimize your Nginx configuration for various scenarios. Always ensure you understand the implications of each configuration and test thoroughly before deploying in a production environment.


66. Enabling Gzip Compression for Different MIME Types:

```nginx
server {
    listen 80;
    server_name example.com;

    gzip on;
    gzip_types text/plain text/css application/json application/javascript;
    
    location / {
        root /var/www/html;
        index index.html;
    }
}
```

67. Setting Up Nginx as a Reverse Proxy with Load Balancing and Health Checks:

```nginx
upstream backend_servers {
    server backend1.example.com max_fails=3 fail_timeout=10s;
    server backend2.example.com max_fails=3 fail_timeout=10s;
}

server {
    listen 80;
    server_name app.example.com;

    location / {
        proxy_pass http://backend_servers;
    }
}
```

68. Using the SSL Early Data Feature:

```nginx
server {
    listen 443 ssl;
    server_name secure.example.com;

    ssl_certificate /etc/nginx/ssl/server.crt;
    ssl_certificate_key /etc/nginx/ssl/server.key;

    ssl_early_data on;

    location / {
        root /var/www/secure;
        index index.html;
    }
}
```

69. Configuring Nginx as a Load Balancer with Least Connections Algorithm:

```nginx
upstream backend_servers {
    least_conn;
    server backend1.example.com;
    server backend2.example.com;
    server backend3.example.com;
}

server {
    listen 80;
    server_name loadbalancer.example.com;

    location / {
        proxy_pass http://backend_servers;
    }
}
```

70. Using Substitution Module to Modify Responses:

```nginx
http {
    sub_filter 'old_string' 'new_string';
    sub_filter_once off;

    server {
        listen 80;
        server_name example.com;

        location / {
            root /var/www/html;
            index index.html;
        }
    }
}
```

Feel free to incorporate these advanced Nginx configuration examples into your setup according to your needs. Remember to thoroughly test your configurations before deploying them in a production environment.


71. Caching Dynamic Content with FastCGI Cache:

```nginx
http {
    fastcgi_cache_path /var/cache/nginx levels=1:2 keys_zone=my_cache:10m;

    server {
        listen 80;
        server_name example.com;

        location ~ \.php$ {
            fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
            fastcgi_cache my_cache;
            fastcgi_cache_valid 200 5m;
            fastcgi_cache_methods GET HEAD;
            add_header X-Fastcgi-Cache $upstream_cache_status;
        }

        location / {
            root /var/www/html;
            index index.html;
        }
    }
}
```

72. Restricting Access to Specific User Agents:

```nginx
server {
    listen 80;
    server_name example.com;

    if ($http_user_agent ~* (bot|spider)) {
        return 403;
    }

    location / {
        root /var/www/html;
        index index.html;
    }
}
```

73. Using Nginx as a Content Security Policy (CSP) Proxy:

```nginx
server {
    listen 80;
    server_name example.com;

    location / {
        proxy_pass http://backend_server;
        add_header Content-Security-Policy "default-src 'self'; script-src 'self' example.com; img-src 'self' data:;";
    }
}
```

74. Configuring Nginx as a Reverse Proxy with SSL Offloading:

```nginx
server {
    listen 80;
    server_name example.com;

    location / {
        proxy_pass http://backend_server;
    }
}

server {
    listen 443 ssl;
    server_name example.com;

    ssl_certificate /etc/nginx/ssl/server.crt;
    ssl_certificate_key /etc/nginx/ssl/server.key;

    location / {
        proxy_pass http://backend_server;
    }
}
```

75. Using the Echo Module for Testing and Debugging:

```nginx
http {
    server {
        listen 80;
        server_name test.example.com;

        location /echo {
            echo "Hello, Nginx!";
        }

        location / {
            root /var/www/html;
            index index.html;
        }
    }
}
```

These advanced examples showcase the depth and versatility of Nginx configuration options. As you use them, remember to tailor the configurations to your specific needs and thoroughly test before deploying them in a production environment.


76. Handling Server Name Indication (SNI) for Multiple SSL Certificates:

```nginx
server {
    listen 443 ssl;
    server_name example.com;

    ssl_certificate /etc/nginx/ssl/example.com.crt;
    ssl_certificate_key /etc/nginx/ssl/example.com.key;

    location / {
        root /var/www/html;
        index index.html;
    }
}

server {
    listen 443 ssl;
    server_name sub.example.com;

    ssl_certificate /etc/nginx/ssl/sub.example.com.crt;
    ssl_certificate_key /etc/nginx/ssl/sub.example.com.key;

    location / {
        root /var/www/sub;
        index index.html;
    }
}
```

77. Configuring HSTS with IncludeSubDomains and Preload:

```nginx
server {
    listen 443 ssl;
    server_name secure.example.com;

    ssl_certificate /etc/nginx/ssl/server.crt;
    ssl_certificate_key /etc/nginx/ssl/server.key;
    
    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;

    location / {
        root /var/www/secure;
        index index.html;
    }
}
```

78. Configuring Proxy Buffering and Cache Bypass:

```nginx
server {
    listen 80;
    server_name proxy.example.com;

    location / {
        proxy_pass http://backend_server;
        proxy_buffering on;
        proxy_buffers 8 16k;
        proxy_buffer_size 32k;
        proxy_cache_bypass $http_upgrade;
    }
}
```

79. Using the HttpHeadersMoreModule:

```nginx
http {
    more_set_headers "Server: MyCustomServer";

    server {
        listen 80;
        server_name example.com;

        location / {
            root /var/www/html;
            index index.html;
        }
    }
}
```

80. Using the ngx_http_auth_request_module for Dynamic Authentication:

```nginx
location /private {
    auth_request /auth;
    root /var/www/private;
    index index.html;
}

location = /auth {
    internal;
    proxy_pass http://auth_backend;
    proxy_pass_request_body off;
    proxy_set_header Content-Length "";
    proxy_set_header X-Original-URI $request_uri;
}
```

These advanced examples demonstrate Nginx's power and flexibility for handling various configurations and use cases. Be sure to tailor them to your specific requirements and test thoroughly before deploying to production.


81. Using GeoIP2 Module for Country-based Routing:

```nginx
http {
    geoip2 /path/to/GeoIP2-Country.mmdb {
        $geoip2_country_code country;
    }

    server {
        listen 80;
        server_name example.com;

        if ($country = US) {
            proxy_pass http://us_backend;
        }

        if ($country = CA) {
            proxy_pass http://ca_backend;
        }

        location / {
            root /var/www/html;
            index index.html;
        }
    }
}
```

82. Using Map to Route Traffic Based on Query Parameters:

```nginx
http {
    map $arg_source $backend {
        default http://default_backend;
        external http://external_backend;
        internal http://internal_backend;
    }

    server {
        listen 80;
        server_name example.com;

        location / {
            proxy_pass $backend;
        }
    }
}
```

83. Configuring Nginx as a Mail Proxy Server:

```nginx
mail {
    server_name mail.example.com;

    auth_http localhost:8080/auth;
    starttls on;

    ssl_certificate /etc/nginx/ssl/mail.crt;
    ssl_certificate_key /etc/nginx/ssl/mail.key;

    protocol smtp;
    smtp_auth plain login;
    smtp_client_buffer 1m;
    smtp_proxy_timeout 180s;

    proxy_pass_error_message on;

    xclient off;

    server {
        listen 25;
        protocol smtp;
        proxy on;
    }
}
```

These advanced examples showcase some unique features and use cases of Nginx. Be sure to understand the implications of each configuration and adapt them to your specific needs. Always test your configurations thoroughly before deploying them to a production environment.


84. Using the AuthRequest Module for Dynamic Authorization:

```nginx
location /private {
    auth_request /auth;
    auth_request_set $auth_status $upstream_status;
    root /var/www/private;
    index index.html;
}

location = /auth {
    internal;
    proxy_pass http://auth_backend;
    proxy_pass_request_body off;
    proxy_set_header Content-Length "";
    proxy_set_header X-Original-URI $request_uri;
}
```

85. Customizing Error Pages and Responses:

```nginx
error_page 404 /custom404.html;
error_page 500 502 503 504 /custom500.html;

server {
    listen 80;
    server_name example.com;

    location / {
        root /var/www/html;
        index index.html;
    }

    location = /custom404.html {
        root /var/www/errors;
    }

    location = /custom500.html {
        root /var/www/errors;
    }
}
```

86. Configuring WebSocket Load Balancing:

```nginx
upstream websocket_backend {
    server backend1.example.com;
    server backend2.example.com;
}

server {
    listen 80;
    server_name socket.example.com;

    location / {
        proxy_pass http://websocket_backend;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}
```

87. Using the Nginx Stream Module for TCP Load Balancing:

```nginx
stream {
    upstream tcp_backend {
        server backend1.example.com:12345;
        server backend2.example.com:12345;
    }

    server {
        listen 12345;
        proxy_pass tcp_backend;
    }
}
```

88. Configuring Dynamic SSL Certificates with SNI and Let's Encrypt:

```nginx
server {
    listen 443 ssl;
    server_name *.example.com;

    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

    location / {
        root /var/www/html;
        index index.html;
    }
}
```

Feel free to incorporate these advanced examples into your Nginx setup based on your specific requirements. Always ensure that you understand the configurations and test them thoroughly before deploying them to production.


89. Using Nginx to Serve Docker Registries:

```nginx
server {
    listen 443 ssl;
    server_name registry.example.com;

    ssl_certificate /etc/nginx/ssl/server.crt;
    ssl_certificate_key /etc/nginx/ssl/server.key;

    location / {
        proxy_pass http://docker_registry;
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}
```

90. Configuring Nginx for Server Push with HTTP/2:

```nginx
server {
    listen 443 ssl http2;
    server_name example.com;

    ssl_certificate /etc/nginx/ssl/server.crt;
    ssl_certificate_key /etc/nginx/ssl/server.key;

    location / {
        root /var/www/html;
        index index.html;
        http2_push /css/styles.css;
        http2_push /js/main.js;
    }
}
```

91. Configuring IP Hash Load Balancing:

```nginx
upstream backend_servers {
    ip_hash;
    server backend1.example.com;
    server backend2.example.com;
    server backend3.example.com;
}

server {
    listen 80;
    server_name app.example.com;

    location / {
        proxy_pass http://backend_servers;
    }
}
```

92. Using the ngx_http_js_module for JavaScript-Based Configuration:

```nginx
location /dynamic {
    js_content dynamic_config;
}

js_include /path/to/config.js;
```

`/path/to/config.js`:
```javascript
function dynamic_config(r) {
    r.return(200, "Dynamic configuration content");
}
```

93. Limiting Connections Based on a Variable:

```nginx
http {
    map $http_user_agent $conn_limit {
        default 10;
        ~MSIE 2;
    }

    server {
        listen 80;
        server_name example.com;

        limit_conn conn_limit_per_ip $conn_limit;
        root /var/www/html;
        index index.html;
    }
}
```

Feel free to use these advanced examples to further customize your Nginx configuration for specific use cases. Always ensure to test and understand each configuration before deploying them in a production environment.

  1. Entering the English page