Skip to content

Hosting an image proxy server for Pixiv

If you prefer not to rely on third-party image proxy servers, you can set up your own! By hosting your own proxy server, you can access images from Pixiv by simply changing the Referer to https://www.pixiv.net/.

By hosting your own Pixiv image proxy server, you can have more control over the caching and access to Pixiv images without relying on external services.

nginx

To set up an image proxy server using nginx, follow these steps:

1. Configure the proxy cache path

Set the cache path and parameters using the proxy_cache_path directive under the http context:

Nginx Configuration File
proxy_cache_path /path/to/cache levels=1:2 keys_zone=pximg:10m max_size=10g inactive=7d use_temp_path=off;

2. Set up the server block

Nginx Configuration File
server {
    listen 443 ssl http2;

    ssl_certificate /path/to/ssl_certificate.crt;
    ssl_certificate_key /path/to/ssl_certificate.key;

    server_name pximg.example.com; # (1)!
    access_log off;

    location / {
        proxy_cache pximg;
        proxy_pass https://i.pximg.net;
        proxy_cache_revalidate on;
        proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
        proxy_cache_lock on;
        add_header X-Cache-Status $upstream_cache_status;
        proxy_set_header Host i.pximg.net;
        proxy_set_header Referer "https://www.pixiv.net/";
        proxy_set_header User-Agent "Mozilla/5.0 (Windows NT 10.0; rv:122.0) Gecko/20100101 Firefox/122.0";

        proxy_cache_valid 200 7d;
        proxy_cache_valid 404 5m;
    }
}
  1. Replace pximg.example.com with your desired domain.

Cloudflare Workers

Alternatively, you can set up an image proxy server using Cloudflare Workers:

JavaScript
addEventListener("fetch", event => {
  event.respondWith(handleRequest(event.request));
});

async function handleRequest(originalRequest) {
  try {
    let url = new URL(originalRequest.url);
    url.hostname = "i.pximg.net";

    let modifiedRequest = new Request(url, originalRequest);
    let response = await fetch(modifiedRequest, {
      headers: {
        'Referer': 'https://www.pixiv.net/',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; rv:122.0) Gecko/20100101 Firefox/122.0'
      }
    });

    if (!response.ok) {
      return new Response("Error fetching the resource.", { status: response.status });
    }

    return response;
  } catch (error) {
    console.error("Failed to fetch resource: ", error.message);

    return new Response("An error occurred while fetching the resource.", { status: 500 });
  }
}

Using the proxy server

Once you have set up your image proxy server, you can access Pixiv images by replacing the original domain with your proxy server domain:

Additional resources