# How to Edit Nginx.conf to Increase File Size Upload

To increase the maximum file size upload in Nginx, you'll need to modify the `nginx.conf` file to adjust the `client_max_body_size` directive. This directive controls the maximum size of the client request body, including file uploads.

Here’s a step-by-step guide on how to edit `nginx.conf` to increase the file size upload limit:

### **1. Locate the `nginx.conf` File**

First, find the `nginx.conf` file that your Nginx instance is using. Here’s how:

**Check with Nginx Command:**

```bash
nginx -t
```

**Output Example:**

```
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
```

This output shows the path to your configuration file.

### **2. Edit the `nginx.conf` File**

Open the `nginx.conf` file using a text editor with appropriate permissions.

**Common Locations for `nginx.conf`:**

- **Debian/Ubuntu/CentOS/Fedora:** `/etc/nginx/nginx.conf`
- **Alternate Locations:** `/usr/local/nginx/conf/nginx.conf`, `/usr/local/etc/nginx/nginx.conf`

**Command to Edit:**

```bash
sudo nano /etc/nginx/nginx.conf
```

**Or use another text editor:**

```bash
sudo vim /etc/nginx/nginx.conf
```

### **3. Increase `client_max_body_size`**

Locate the `http` block or `server` block where you want to set the maximum file size. Add or update the `client_max_body_size` directive to increase the allowed size.

**Example Configuration:**

```
http {
    # Other configurations...

    client_max_body_size 100M;  # Increase the size limit to 100MB

    # Other configurations...
}

```

**Explanation:**

- **`client_max_body_size`**: This directive sets the maximum allowed size of the client request body, including file uploads. The size can be specified in megabytes (M) or gigabytes (G).

### **4. Restart Nginx**

After making changes to the `nginx.conf` file, restart Nginx to apply the new configuration.

**Restart Command:**

```bash
sudo systemctl restart nginx
```

**Alternative Command (if using init.d):**

```bash
sudo service nginx restart
```

### **5. Verify Changes**

To confirm that the changes have been applied:

1. **Check Nginx Error Logs:** Ensure there are no errors related to the configuration.
    
    **Command:**
    
    ```bash
    sudo tail -f /var/log/nginx/error.log
    ```
    
2. **Test File Upload:** Attempt to upload a file larger than the previous limit to verify that the new limit is effective.

### **6. Adjust Other Related Settings**

If you're using a web application that also has file upload size limits, make sure to adjust those settings as well:

- **For PHP (if using PHP-FPM):** Update `upload_max_filesize` and `post_max_size` in `php.ini`.
- **For Node.js:** Configure body size limits in your application code.

**Example for PHP (in `php.ini`):**

```
upload_max_filesize = 100M
post_max_size = 100M
```

**Example for Node.js (Express.js):**

```jsx
const express = require('express');
const app = express();

app.use(express.json({ limit: '100mb' }));
app.use(express.urlencoded({ limit: '100mb', extended: true }));

// Your routes and other settings
```

### **Summary**

To increase file size upload limits in Nginx:

1. **Locate `nginx.conf`:** Use `nginx -t` or check common locations.
2. **Edit `nginx.conf`:** Add or update `client_max_body_size` in the `http` block or specific `server` block.
3. **Restart Nginx:** Apply changes by restarting the service.
4. **Verify Changes:** Check logs and test file uploads.
5. **Adjust Related Settings:** Ensure application-level settings are consistent with the new limit.

By following these steps, you can effectively increase the file size upload limit for your Nginx server.