Nginx documentation

From Server rent store
Jump to navigation Jump to search
  1. Nginx Documentation

This article provides a comprehensive overview of configuring Nginx as a reverse proxy and web server for a MediaWiki installation. It is geared towards newcomers to server administration and aims to provide a clear, step-by-step guide. Understanding Nginx configuration is crucial for performance, security, and scalability of your wiki.

Why Use Nginx with MediaWiki?

MediaWiki can be served directly by Apache, but Nginx offers several advantages:

  • Performance: Nginx excels at serving static content and handling a large number of concurrent connections with minimal resource usage.
  • Reverse Proxy: Nginx can act as a reverse proxy, forwarding requests to the PHP interpreter and caching static content, reducing the load on the MediaWiki server itself.
  • Security: Nginx can be configured to handle SSL/TLS encryption, protect against common web attacks, and limit access to specific resources.
  • Load Balancing: Nginx can distribute traffic across multiple MediaWiki servers (useful for high-traffic wikis).

Basic Nginx Configuration

The primary Nginx configuration file is typically located at `/etc/nginx/nginx.conf`. However, it's best practice to create a separate site configuration file for your MediaWiki installation, typically in `/etc/nginx/sites-available/`. You then create a symbolic link to this file in `/etc/nginx/sites-enabled/` to activate it.

Here’s a basic configuration example:

```nginx server {

   listen 80;
   server_name yourwiki.example.com;
   root /var/www/mediawiki;
   index index.php;
   location / {
       try_files $uri $uri/ /index.php?$args;
   }
   location ~ \.php$ {
       include snippets/fastcgi-php.conf;
       fastcgi_pass unix:/run/php/php7.4-fpm.sock;  # Adjust PHP version as needed
   }
   location ~ /\.ht {
       deny all;
   }

} ```

This configuration listens on port 80, serves content from `/var/www/mediawiki`, and uses PHP-FPM to process PHP files. The `try_files` directive is crucial for MediaWiki’s URL rewriting.

Detailed Configuration Parameters

Let's break down some key configuration parameters and their recommended values.

Parameter Description Recommended Value
`listen` The port Nginx listens on. `80` (HTTP) or `443` (HTTPS)
`server_name` The domain name or IP address of your wiki. `yourwiki.example.com`
`root` The directory where your MediaWiki files are located. `/var/www/mediawiki`
`index` The default file to serve if no specific file is requested. `index.php`
`location /` Handles all requests. `try_files $uri $uri/ /index.php?$args;`

SSL/TLS Configuration (HTTPS)

Securing your wiki with HTTPS is highly recommended. You can use Let's Encrypt to obtain free SSL/TLS certificates. Here's an example configuration snippet:

```nginx server {

   listen 443 ssl;
   server_name yourwiki.example.com;
   ssl_certificate /etc/letsencrypt/live/yourwiki.example.com/fullchain.pem;
   ssl_certificate_key /etc/letsencrypt/live/yourwiki.example.com/privkey.pem;
   # ... (rest of the configuration) ...

} ```

Remember to redirect HTTP traffic to HTTPS:

```nginx server {

   listen 80;
   server_name yourwiki.example.com;
   return 301 https://$host$request_uri;

} ```

Performance Tuning

Nginx offers several options for performance tuning.

Parameter Description Recommended Value
`keepalive_timeout` Time to keep a persistent connection open. `65` seconds
`client_max_body_size` Maximum size of a client request body (e.g., for file uploads). `20M` (adjust based on upload limits in MediaWiki)
`gzip` Enables gzip compression for static content. `on`
`proxy_cache_path` Defines a cache directory for frequently accessed content. `/var/cache/nginx; keys_zone=mediawiki_cache:100m;`

Caching Configuration

Caching frequently accessed content can significantly improve performance. Nginx can cache static assets and even dynamically generated content. Here's an example:

```nginx proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=mediawiki_cache:100m inactive=60m max_size=1g; proxy_cache_key "$scheme$request_method$host$request_uri";

location / {

   try_files $uri $uri/ @mediawiki;

}

location @mediawiki {

   proxy_pass http://127.0.0.1:80; #Or the address of your PHP-FPM
   proxy_set_header Host $host;
   proxy_set_header X-Real-IP $remote_addr;
   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
   proxy_cache mediawiki_cache;
   proxy_cache_valid 200 302 60m;
   proxy_cache_valid 404 1m;
   proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;

} ```

This configuration caches responses from the MediaWiki server in `/var/cache/nginx`.

Important Considerations


Intel-Based Server Configurations

Configuration Specifications Benchmark
Core i7-6700K/7700 Server 64 GB DDR4, NVMe SSD 2 x 512 GB CPU Benchmark: 8046
Core i7-8700 Server 64 GB DDR4, NVMe SSD 2x1 TB CPU Benchmark: 13124
Core i9-9900K Server 128 GB DDR4, NVMe SSD 2 x 1 TB CPU Benchmark: 49969
Core i9-13900 Server (64GB) 64 GB RAM, 2x2 TB NVMe SSD
Core i9-13900 Server (128GB) 128 GB RAM, 2x2 TB NVMe SSD
Core i5-13500 Server (64GB) 64 GB RAM, 2x500 GB NVMe SSD
Core i5-13500 Server (128GB) 128 GB RAM, 2x500 GB NVMe SSD
Core i5-13500 Workstation 64 GB DDR5 RAM, 2 NVMe SSD, NVIDIA RTX 4000

AMD-Based Server Configurations

Configuration Specifications Benchmark
Ryzen 5 3600 Server 64 GB RAM, 2x480 GB NVMe CPU Benchmark: 17849
Ryzen 7 7700 Server 64 GB DDR5 RAM, 2x1 TB NVMe CPU Benchmark: 35224
Ryzen 9 5950X Server 128 GB RAM, 2x4 TB NVMe CPU Benchmark: 46045
Ryzen 9 7950X Server 128 GB DDR5 ECC, 2x2 TB NVMe CPU Benchmark: 63561
EPYC 7502P Server (128GB/1TB) 128 GB RAM, 1 TB NVMe CPU Benchmark: 48021
EPYC 7502P Server (128GB/2TB) 128 GB RAM, 2 TB NVMe CPU Benchmark: 48021
EPYC 7502P Server (128GB/4TB) 128 GB RAM, 2x2 TB NVMe CPU Benchmark: 48021
EPYC 7502P Server (256GB/1TB) 256 GB RAM, 1 TB NVMe CPU Benchmark: 48021
EPYC 7502P Server (256GB/4TB) 256 GB RAM, 2x2 TB NVMe CPU Benchmark: 48021
EPYC 9454P Server 256 GB RAM, 2x2 TB NVMe

Order Your Dedicated Server

Configure and order your ideal server configuration

Need Assistance?

⚠️ *Note: All benchmark scores are approximate and may vary based on configuration. Server availability subject to stock.* ⚠️