Nginx

From Server rent store
Jump to navigation Jump to search
  1. Nginx Configuration for MediaWiki

This article details configuring Nginx as a reverse proxy and web server for a MediaWiki 1.40 installation. Nginx is a popular choice due to its performance, stability, and low resource consumption. This guide assumes you have a basic understanding of server administration and Linux command-line interface. It also assumes you have a functioning PHP installation and a MariaDB or MySQL database server set up for MediaWiki.

== Why Use Nginx with MediaWiki?

While MediaWiki can be served directly by Apache, using Nginx as a reverse proxy provides several benefits:

  • **Improved Performance:** Nginx excels at serving static content and efficiently handling concurrent connections.
  • **Load Balancing:** Nginx can distribute traffic across multiple backend MediaWiki instances for increased scalability.
  • **Security:** Nginx can act as a first line of defense against common web attacks.
  • **SSL/TLS Termination:** Nginx can handle SSL/TLS encryption and decryption, reducing the load on the MediaWiki server.
  • **Caching:** Nginx can cache frequently accessed content, further improving performance.

== Prerequisites

Before you begin, ensure you have:

  • A server with a Linux distribution (e.g., Ubuntu, Debian, CentOS).
  • Nginx installed and running. Instructions vary depending on your distribution.
  • PHP installed with the necessary extensions for MediaWiki (e.g., `php-mysql`, `php-gd`, `php-xml`).
  • MediaWiki 1.40 installed and configured, but *not* directly accessible via the web.
  • Root or sudo access to the server.


== Basic Nginx Configuration

The core of the Nginx configuration involves creating a server block that listens for incoming requests and proxies them to the MediaWiki backend. Here's a basic configuration example:

```nginx server {

   listen 80;
   server_name your.mediawiki.domain;
   location / {
       proxy_pass http://127.0.0.1:8080;  # Assuming MediaWiki runs on port 8080
       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_set_header X-Forwarded-Proto $scheme;
   }

} ```

Replace `your.mediawiki.domain` with your actual domain name and `8080` with the port MediaWiki is listening on. This basic configuration forwards all requests to the MediaWiki server running on the same machine.

== Advanced Configuration Options

Several advanced options can enhance the Nginx configuration for MediaWiki:

  • **SSL/TLS:** Enable HTTPS by configuring SSL/TLS certificates.
  • **Caching:** Cache static assets (images, CSS, JavaScript) to reduce server load.
  • **Gzip Compression:** Compress responses to reduce bandwidth usage.
  • **Security Headers:** Add security headers to protect against common web vulnerabilities.
  • **File Serving:** Serve static files directly from Nginx for optimal performance.

== Key Configuration Parameters

Here's a table detailing important Nginx configuration parameters for MediaWiki:

Parameter Description Default Value
`listen` The port Nginx listens on. 80
`server_name` The domain name or IP address Nginx responds to. `_` (any hostname)
`proxy_pass` The URL of the backend MediaWiki server. N/A
`proxy_set_header` Sets HTTP headers to be passed to the backend server. N/A
`client_max_body_size` The maximum allowed size of the client request body. Important for file uploads. 1MB
`gzip` Enables Gzip compression for responses. Off

== Example: Configuring SSL/TLS

To enable SSL/TLS, you'll need an SSL certificate. Let's Encrypt is a popular free option. Here's an example configuration:

```nginx server {

   listen 443 ssl;
   server_name your.mediawiki.domain;
   ssl_certificate /etc/letsencrypt/live/your.mediawiki.domain/fullchain.pem;
   ssl_certificate_key /etc/letsencrypt/live/your.mediawiki.domain/privkey.pem;
   location / {
       proxy_pass http://127.0.0.1:8080;
       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_set_header X-Forwarded-Proto $scheme;
   }

}

server {

   listen 80;
   server_name your.mediawiki.domain;
   return 301 https://$host$request_uri;

} ```

This configuration redirects all HTTP traffic to HTTPS and uses the specified SSL certificates.

== Example: Configuring Caching

Nginx can cache static assets to improve performance. Here is an example snippet:

```nginx location ~* \.(jpg|jpeg|png|gif|css|js|ico)$ {

   expires 30d;
   add_header Cache-Control "public";

} ```

This configuration sets a cache expiry of 30 days for common static file types.

== Important Considerations and Troubleshooting

  • **`$wgServer` in LocalSettings.php:** In your MediaWiki `LocalSettings.php` file, ensure the `$wgServer` variable is set correctly to your public Nginx address (e.g., ` $wgServer = "https://your.mediawiki.domain";`).
  • **`$wgScriptPath` in LocalSettings.php:** Verify `$wgScriptPath` is set appropriately. Usually, this is `/`.
  • **File Uploads:** Increase `client_max_body_size` in your Nginx configuration if you experience issues with file uploads.
  • **Permissions:** Ensure Nginx has the necessary permissions to access the MediaWiki files.
  • **Logs:** Check the Nginx error logs (`/var/log/nginx/error.log`) and MediaWiki logs for troubleshooting.
  • **PHP-FPM:** If you're using PHP-FPM, ensure it's properly configured and running.

== Nginx Configuration File Locations

Operating System Default Nginx Configuration Directory
Ubuntu/Debian `/etc/nginx/sites-available/` and `/etc/nginx/sites-enabled/`
CentOS/RHEL `/etc/nginx/conf.d/`
Fedora `/etc/nginx/conf.d/`

== Performance Tuning

Parameter Description Suggested Value
`worker_processes` Number of worker processes. Number of CPU cores
`worker_connections` Maximum number of connections per worker process. 1024 - 4096
`keepalive_timeout` Timeout for keep-alive connections. 65
`proxy_buffer_size` Initial buffer size for proxying. 128k
`proxy_buffers` Number and size of proxy buffers. 4 256k

This article provides a starting point for configuring Nginx with MediaWiki. Refer to the official Nginx documentation and MediaWiki documentation for more detailed information. Remember to test your configuration thoroughly after making any changes.

Special:MyLanguage/Server_configuration:_Nginx Help:Contents Manual:Configuration Manual:Installing_and_configuring_PHP Manual:Installing_and_configuring_MySQL Manual:Configuring_a_web_server Manual:Reverse proxy Manual:Extension installation Manual:LocalSettings.php Manual:Default settings Manual:Upgrading Help:FAQ


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.* ⚠️