When deploying a project with [DeployHQ](https://www.deployhq.com), you can [exclude files and directories](https://www.deployhq.com/blog/excluding-files-with-deployignore) from being uploaded. But what happens when different servers need different files? Your production server might not need test fixtures, your staging server might need a debug config that production shouldn't have, and your static asset server doesn't need backend code at all.

With **per-server exclusion rules** , you can define exactly which files reach each deployment target.

## How it works

[DeployHQ](https://www.deployhq.com) lets you set exclusion rules at two levels:

```
flowchart TD
    A[Repository] --> B{Project-Level Exclusions}
    B --> C[Files filtered for ALL servers]
    C --> D{Per-Server Exclusions}
    D --> E[Production Server<br/>Additional rules applied]
    D --> F[Staging Server<br/>Different rules applied]
    D --> G[Asset Server<br/>Its own rules applied]
```

- **Project-level exclusions** apply to every server in the project (configured in Settings → Excluded Files, or via [`.deployignore`](https://www.deployhq.com/blog/excluding-files-with-deployignore))
- **Per-server exclusions** apply only to a specific server, on top of the project-level rules

When you add an exclusion rule through the UI, you'll see an option: **Exclude this file on all current and future servers?**. Uncheck this to make the rule apply only to the server you're currently editing.

## Common use cases

### Different configs per environment

Your production server shouldn't receive development or testing configuration:

| File | Production | Staging | Dev |
| --- | --- | --- | --- |
| `.env.production` | ✅ Deploy | ❌ Exclude | ❌ Exclude |
| `.env.staging` | ❌ Exclude | ✅ Deploy | ❌ Exclude |
| `.env.development` | ❌ Exclude | ❌ Exclude | ✅ Deploy |
| `debug.config.php` | ❌ Exclude | ✅ Deploy | ✅ Deploy |

### Backend vs frontend servers

If you deploy the same repository to separate backend and frontend servers:

**Frontend server exclusions:**

```
app/controllers/**
app/models/**
database/**
config/database.yml
Procfile
```

**Backend server exclusions:**

```
public/assets/**
public/images/**
node_modules/**
webpack.config.js
package.json
```

### Static asset server

A CDN origin or static file server only needs compiled assets:

```
app/**
config/**
database/**
tests/**
vendor/**
*.php
*.rb
*.py
Gemfile
Gemfile.lock
composer.json
composer.lock
```

## Setting up per-server exclusions

1. Navigate to your project in [DeployHQ](https://www.deployhq.com)
2. Go to **Settings → Excluded Files**
3. Click **Add a New Exclusion Rule**
4. Enter your file pattern (e.g. `config/database.yml`)
5. **Uncheck** Exclude this file on all current and future servers?
6. Select the specific server(s) this rule should apply to
7. Click **Save**

The same [pattern syntax](https://www.deployhq.com/blog/whitelisting-excluded-files) applies as regular exclusions — wildcards (`*`, `**`), directory matching, and [whitelisting with `!`](https://www.deployhq.com/blog/whitelisting-excluded-files) all work.

## Per-server vs `.deployignore`

One important distinction: the [`.deployignore` file](https://www.deployhq.com/blog/excluding-files-with-deployignore) applies to **all servers** in a project. If you need server-specific rules, you must use the Excluded Files UI.

A common approach is to combine both:

| Method | Scope | Version controlled |
| --- | --- | --- |
| `.deployignore` | All servers | Yes — in your repository |
| Project-level UI exclusions | All servers | No — in DeployHQ settings |
| Per-server UI exclusions | Specific servers only | No — in DeployHQ settings |

Use `.deployignore` for universal rules (like excluding `node_modules` or `tests`), and per-server exclusions for environment-specific files.

## Verifying your rules

After a deployment, check the log under the Generate Manifest step. [DeployHQ](https://www.deployhq.com) shows excluded files per server, so you can confirm each server received the right set of files.

For the full documentation, see our [support article on excluded files](https://www.deployhq.com/support/excluded-files).

## Related guides

- [Excluding files with .deployignore](https://www.deployhq.com/blog/excluding-files-with-deployignore) — version-controlled exclusion rules
- [Whitelisting excluded files](https://www.deployhq.com/blog/whitelisting-excluded-files) — create exceptions with the `!` prefix
- [Stop certain files from being uploaded](https://www.deployhq.com/blog/stop-certain-files-from-being-uploaded-during-a-deployment) — basics of file exclusions
- [Deploying to multiple servers at the same time](https://www.deployhq.com/blog/deploying-to-multiple-servers-at-the-same-time) — multi-server deployments
- [Protect your environments: practical security tips](https://www.deployhq.com/blog/protect-your-environments-practical-security-tips-for-smarte) — keep secrets out of deployments

* * *

Ready to streamline your multi-server deployments? [Sign up for DeployHQ](https://www.deployhq.com/signup) and get started in minutes. If you have any questions, reach out to us at [support@deployhq.com](mailto:support@deployhq.com) or on [Twitter/X @deployhq](https://x.com/deployhq).

