CORS problems on OVH usually aren’t really “OVH problems.” They’re deployment-shape problems: shared hosting with Apache overrides, VPS setups with Nginx in front of PHP-FPM, CDN or reverse proxy layers, and apps that work locally but break once a browser starts sending preflights.

I’ve seen the same mistakes over and over. The browser says “blocked by CORS policy,” people start randomly adding Access-Control-Allow-Origin: *, and things get worse.

Here’s the stuff that actually breaks on OVH deployments, and how to fix it.

Mistake #1: Setting CORS in app code but forgetting the web server

This is probably the most common one.

You add headers in PHP, Node, or whatever backend you’re using:

<?php
header('Access-Control-Allow-Origin: https://app.example.com');
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type, Authorization');

Looks fine. Then preflight requests still fail.

Why? Because on OVH, Apache or Nginx may intercept OPTIONS before your app ever sees it. Or a 403/404 error page gets returned without your CORS headers. Browsers don’t care that your normal GET route includes the right headers if the preflight died earlier.

Fix

Set CORS at the web server layer for routes that need it, or make sure OPTIONS reaches your app.

Apache on OVH shared hosting or VPS

<IfModule mod_headers.c>
    Header always set Access-Control-Allow-Origin "https://app.example.com"
    Header always set Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS"
    Header always set Access-Control-Allow-Headers "Content-Type, Authorization"
</IfModule>

RewriteEngine On
RewriteCond %{REQUEST_METHOD} OPTIONS
RewriteRule ^(.*)$ $1 [R=204,L]

If you use .htaccess, Header always set matters. Without always, error responses often miss CORS headers.

Mistake #2: Using * with credentials

This one is a classic. Someone enables cookies or sends Authorization headers, then keeps this config:

Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true

That combination is invalid. Browsers reject it.

You can use * only for truly public responses with no credentials. GitHub’s public API is a good example of that model. Real response headers from api.github.com include:

access-control-allow-origin: *
access-control-expose-headers: ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset, Warning

That works because the API is designed for cross-origin access without browser credentials by default.

Fix

If you need cookies or auth headers, return the exact origin, not *.

<?php
$allowedOrigins = [
    'https://app.example.com',
    'https://admin.example.com',
];

$origin = $_SERVER['HTTP_ORIGIN'] ?? '';

if (in_array($origin, $allowedOrigins, true)) {
    header("Access-Control-Allow-Origin: $origin");
    header('Access-Control-Allow-Credentials: true');
    header('Vary: Origin');
}

That Vary: Origin header is not optional when you dynamically reflect origins. Without it, caches can serve the wrong CORS response to the wrong site.

Mistake #3: Forgetting preflight requests entirely

A request becomes “non-simple” fast. Add Authorization, use PUT, send JSON with Content-Type: application/json, and the browser sends an OPTIONS preflight first.

A lot of OVH deployments only test with Postman or curl. Those tools don’t enforce browser CORS rules, so everything looks healthy until frontend code hits it.

Fix

Handle OPTIONS cleanly and return the right headers with a 200 or 204.

PHP example

<?php
$allowedOrigins = ['https://app.example.com'];
$origin = $_SERVER['HTTP_ORIGIN'] ?? '';

if (in_array($origin, $allowedOrigins, true)) {
    header("Access-Control-Allow-Origin: $origin");
    header('Access-Control-Allow-Credentials: true');
    header('Access-Control-Allow-Methods: GET, POST, PUT, PATCH, DELETE, OPTIONS');
    header('Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With');
    header('Access-Control-Max-Age: 86400');
    header('Vary: Origin');
}

if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
    http_response_code(204);
    exit;
}

If your frontend sends custom headers, they must appear in Access-Control-Allow-Headers. Otherwise the browser blocks the real request before it even starts.

Mistake #4: Missing CORS headers on error responses

This one is nasty because it hides the real bug.

Your API returns a 500 or 403, but without Access-Control-Allow-Origin. The browser reports a CORS failure, and now you’re debugging the wrong thing.

On OVH Apache setups, this happens a lot when headers are set only for successful responses.

Fix

Use server config that applies headers to all responses.

Apache

<IfModule mod_headers.c>
    Header always set Access-Control-Allow-Origin "https://app.example.com"
    Header always set Access-Control-Allow-Credentials "true"
    Header always set Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS"
    Header always set Access-Control-Allow-Headers "Content-Type, Authorization"
</IfModule>

Nginx

location /api/ {
    add_header Access-Control-Allow-Origin https://app.example.com always;
    add_header Access-Control-Allow-Credentials true always;
    add_header Access-Control-Allow-Methods "GET, POST, PUT, PATCH, DELETE, OPTIONS" always;
    add_header Access-Control-Allow-Headers "Content-Type, Authorization" always;

    if ($request_method = OPTIONS) {
        return 204;
    }

    proxy_pass http://127.0.0.1:8080;
}

The always flag matters here too.

Mistake #5: Reflecting any origin blindly

I get why people do this. It “fixes” the browser error quickly:

header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']);
header('Access-Control-Allow-Credentials: true');

That’s effectively turning your authenticated API into a cross-origin free-for-all if cookies are involved. Bad idea.

Fix

Use an allowlist. Be strict. Match full origins including scheme.

<?php
$allowedOrigins = [
    'https://app.example.com',
    'https://staging-app.example.com',
];

$origin = $_SERVER['HTTP_ORIGIN'] ?? null;

if ($origin && in_array($origin, $allowedOrigins, true)) {
    header("Access-Control-Allow-Origin: $origin");
    header('Access-Control-Allow-Credentials: true');
    header('Vary: Origin');
}

If you need broader matching for tenant subdomains, parse and validate carefully instead of using loose substring checks.

Mistake #6: Not exposing response headers the frontend actually needs

By default, browser JavaScript can only read a limited set of response headers. If your frontend needs ETag, pagination links, rate limit headers, or custom IDs, you must expose them.

This gets missed a lot on APIs deployed behind OVH infrastructure because the request itself succeeds, but frontend code sees null when reading the header.

GitHub does this correctly. Their API exposes a long list of useful headers:

access-control-expose-headers: ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset, Warning

Fix

Expose only what the frontend needs.

Access-Control-Expose-Headers: ETag, Link, X-Request-Id, X-RateLimit-Remaining

Nginx example

add_header Access-Control-Expose-Headers "ETag, Link, X-Request-Id" always;

Mistake #7: Breaking CORS with redirects

OVH deployments often involve forced HTTPS, www to apex redirects, or app-to-app routing changes. If your API request hits a redirect first, CORS can get weird fast, especially on preflight requests.

I’ve seen this happen with:

  • http://api.example.com redirecting to https://api.example.com
  • /api redirecting to /api/
  • old subdomains redirecting to new ones

Fix

Point the frontend directly at the final API origin and path. Don’t rely on redirects for API calls.

Also make sure OPTIONS doesn’t get redirected by rewrite rules.

Apache example

RewriteEngine On

# Avoid redirecting preflight
RewriteCond %{REQUEST_METHOD} OPTIONS
RewriteRule ^ - [R=204,L]

# Other rewrite rules below

Mistake #8: Ignoring cache behavior

If OVH CDN, a reverse proxy, or even browser caching is involved, CORS responses can get cached in dangerous ways.

The big one: dynamic origin reflection without Vary: Origin.

Request from https://app.example.com gets cached with:

Access-Control-Allow-Origin: https://app.example.com

Then a request from another origin gets the cached response. Now you have either broken behavior or data leakage risk.

Fix

When CORS varies by origin, send:

Vary: Origin

If preflight behavior varies by requested headers or methods, these can matter too:

Vary: Origin, Access-Control-Request-Method, Access-Control-Request-Headers

Not every deployment needs the full set, but Vary: Origin is the one people skip constantly.

Mistake #9: Mixing CORS with CSRF assumptions

CORS is not CSRF protection. I still see teams on OVH shared hosting assume “we locked down Access-Control-Allow-Origin, so we’re safe.”

Nope.

CORS controls whether browser JavaScript can read responses cross-origin. It does not stop a browser from sending certain cross-site requests. If you use cookies for auth, you still need proper CSRF defenses and sane cookie settings.

That’s not strictly a CORS config issue, but it’s where people get burned. If you’re hardening the rest of your headers too, the official browser docs are the place to start, and for adjacent header strategy I’d also check https://csp-guide.com.

A practical baseline for OVH-hosted APIs

If I were deploying a credentialed API on OVH today, I’d start with something like this:

<?php
$allowedOrigins = [
    'https://app.example.com',
    'https://admin.example.com',
];

$origin = $_SERVER['HTTP_ORIGIN'] ?? '';

if (in_array($origin, $allowedOrigins, true)) {
    header("Access-Control-Allow-Origin: $origin");
    header('Access-Control-Allow-Credentials: true');
    header('Access-Control-Allow-Methods: GET, POST, PUT, PATCH, DELETE, OPTIONS');
    header('Access-Control-Allow-Headers: Content-Type, Authorization');
    header('Access-Control-Expose-Headers: ETag, X-Request-Id');
    header('Access-Control-Max-Age: 86400');
    header('Vary: Origin');
}

if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
    http_response_code(204);
    exit;
}

And I’d make sure the web server also preserves those headers on error responses.

What to check first when CORS breaks on OVH

My debugging order is boring, but it works:

  1. Check the browser network tab, not just the console error.
  2. Inspect the OPTIONS preflight if there is one.
  3. Verify the exact Origin sent by the browser.
  4. Check for redirects before the actual API response.
  5. Confirm headers exist on error responses too.
  6. If credentials are used, make sure there’s no *.
  7. If origin reflection is dynamic, confirm Vary: Origin.

Most CORS bugs aren’t subtle. They’re just hidden behind bad error messages and messy deployment layers. On OVH, that usually means checking Apache, Nginx, app code, and any proxy in between instead of staring at frontend code for an hour.