Skip to main content

Nginx Reverse Proxy

Route traffic from your own domain to MageAds services.

Why Use a Reverse Proxy?

Configuring Nginx as a reverse proxy allows you to transparently forward HTTP/HTTPS requests from subpaths of your domain to the corresponding MageAds services. The URL visible in the user's browser remains unchanged.

Key benefits:

  • Avoid resource blocking by browser privacy mechanisms (ITP, ETP)
  • MageAds assets are served under the publisher's domain (first-party context)
  • Better compatibility with third-party cookie policies
  • Greater control over traffic and HTTP headers

URL Mapping

Source (Your Domain)Target (mageads.com)
https://YOURDOMAIN.com/mg/dl/*https://delivery.mageads.com/*
https://YOURDOMAIN.com/mg/st/*https://static.mageads.com/*
https://YOURDOMAIN.com/mg/ia/*https://image.mageads.com/*
https://YOURDOMAIN.com/mg/sn/*https://sync.mageads.com/*
https://YOURDOMAIN.com/mg/ap/*https://api-panel.mageads.com/*
https://YOURDOMAIN.com/mg/md/*https://media.mageads.com/*
info

Replace YOURDOMAIN.com with your actual domain name in all places throughout the configuration.

Nginx Configuration

Add the following location blocks inside the server { } block in the Nginx configuration file for your domain (e.g. /etc/nginx/sites-available/yourdomain.com).

Delivery

location /mg/dl/ {
proxy_pass https://delivery.mageads.com/;
proxy_ssl_server_name on;
proxy_set_header Host delivery.mageads.com;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

Static

location /mg/st/ {
proxy_pass https://static.mageads.com/;
proxy_ssl_server_name on;
proxy_set_header Host static.mageads.com;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

Image

location /mg/ia/ {
proxy_pass https://image.mageads.com/;
proxy_ssl_server_name on;
proxy_set_header Host image.mageads.com;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

Sync

location /mg/sn/ {
proxy_pass https://sync.mageads.com/;
proxy_ssl_server_name on;
proxy_set_header Host sync.mageads.com;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

API Panel

location /mg/ap/ {
proxy_pass https://api-panel.mageads.com/;
proxy_ssl_server_name on;
proxy_set_header Host api-panel.mageads.com;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

Media

location /mg/md/ {
proxy_pass https://media.mageads.com/;
proxy_ssl_server_name on;
proxy_set_header Host media.mageads.com;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

Configuration Parameters

ParameterDescription
proxy_passAddress of the target server to which requests are forwarded
proxy_ssl_server_name onEnables SNI (Server Name Indication) support for SSL/TLS connections — required for shared hosting and CDN
proxy_set_header HostOverrides the Host header with the target MageAds service address
proxy_set_header X-Real-IPForwards the real client IP address to the target server
proxy_set_header X-Forwarded-ForAppends the client IP address to the proxy chain

Deployment Steps

  1. Open the Nginx configuration file for your domain:

    /etc/nginx/sites-available/yourdomain.com
    # or
    /etc/nginx/nginx.conf
  2. Add all location blocks from the Nginx Configuration section inside the server { } block.

  3. Test the configuration syntax:

    nginx -t
  4. Reload Nginx:

    systemctl reload nginx
    # or
    nginx -s reload
  5. Test all URLs listed in the Verification section.

  6. Confirm that the URL in the browser remains unchanged after loading assets.

Verification

After deployment, test the proxy rules by opening the following test URLs (replace YOURDOMAIN.com with your actual domain):

  • https://YOURDOMAIN.com/mg/dl/deviceStorage.json
  • https://YOURDOMAIN.com/mg/st/_a4a.js
  • https://YOURDOMAIN.com/mg/ia/placeholder.png
  • https://YOURDOMAIN.com/mg/sn/robots.txt
  • https://YOURDOMAIN.com/mg/ap/assets/images/shopable-media/icons/chevron-left.svg
  • https://YOURDOMAIN.com/mg/md/publisher_10/media_195.png
tip

Each URL should return an HTTP 200 response with valid content. The URL in the browser address bar should not change to mageads.com.

Troubleshooting

502 Bad Gateway

Nginx cannot connect to the MageAds server. Check:

  • whether the server has internet access and can reach mageads.com,
  • whether the firewall is blocking outbound HTTPS connections (port 443),
  • whether the proxy_pass address ends with a trailing slash /.

SSL/TLS Errors

Make sure the proxy_ssl_server_name on directive is present in every location block. It is required when the target server uses virtual hosting (SNI).

Incorrect URL Redirect

If the target server returns HTTP redirects (30x), add the following to the relevant location block:

proxy_redirect https://delivery.mageads.com/ /mg/dl/;

Support

Email: info@mageads.com
Documentation Version: 1.4