Hongmu Notes
Home Summary of pitfalls When the current site's images return a 404 error, Nginx automatically serves images from the backup site.
Summary of pitfalls

When the current site's images return a 404 error, Nginx automatically serves images from the backup site.

When the current site's images return a 404 error, Nginx automatically serves images from the backup site.
 

You can use the following Nginx configuration to automatically fetch images from a backup site when a 404 error is encountered for an image on this site:

http {
    upstream backup_images {
        server backup.example.com;
    }

    server {
        listen 80;
        server_name example.com;
        root /var/www/html;

        location /images/ {
            try_files $uri @backup;
        }

        location @backup {
            proxy_pass http://backup_images;
        }
    }
}

This configuration willexample.com80Listen on the port and forward all requests to/var/www/htmlIn the directory. All/images/The initial request will be processed. If the image requested by this site does not exist,NginxThe system will automatically forward the request to the backup site.backup.example.comRetrieve images from a backup site.

Note that this configuration is being used.upstreamUse a module to define a backup site. If yourNginxThe version does not come with built-in functionality.upstreamThe module requires manual compilation.NginxTurn onupstreamModule. Additionally, due to the presence of a proxy, the backup site must be configured.CORSStrategy – Allowexample.comOtherwise, the browser will reject the request for images from the backup site.

My Usage

I have two websites: one is the main site, and the other is a backup image site!

The images for the two stations are identical, and the image paths are also the same!

Since there were too many images when backing up the main server and I didn't want to back them up, I decided to separate the images out!

The path for this site is /d/file/ – images are stored there!

The backup route follows the same principle; at this point, the pseudo-static rule is written as follows:

 隐藏内容:付费阅读
if (!-f $request_filename) {
    rewrite ^/d/file/(.*)$ http://localhost/d/file/$1 break;
}

微信赞赏

WeChat

支付宝赞赏

Alipay

✍️ Author: Hong Mu

webmaster · Thanks for reading, stay tuned for more exciting content

Author homepage View home page →

Related articles

Browser caching increases the speed of secondary visits to your website

Browser caching increases the speed of secondary visits to your website Summary of pitfalls

Use browser caching of official words: If users will visit your website multiple times, browser caching of static resources can save users time. Cache headers should be applied to all cacheable static resources, not just to a small subset of static resources (for example, images). Cacheable resources include JS and CSS files, image files, and other binary object files (media files, PDF files, etc.). Normally, HTML doesn’t…
👁 202

Recommended reading

Art Photography Studio Website Template 0519

Art Photography Studio Website Template 0519 Practical Collection Yiyou template

This EyouCMS template is ideal for art photography studios with a visual arts design style, enabling you to showcase your photographic works, artistic style, photography services, and brand story. It helps photography studios present their portfolio online and attract potential clients. Template Demo | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Summary of Common Installation Issues for EyouCMS | EyouCMS...
👁 49
EmpireCMS 7.5 – Generate sitamap.xml mapping plugin

EmpireCMS 7.5 – Generate sitamap.xml mapping plugin Practical Collection empire plugin

First, here's a screenshot: 20251003193735549-sitemap_w8WEJ.tar.gz – Download the.tar.gz file (5.7 KB). The code was found online and has been slightly optimized. First, please ensure that the website address in the system settings is filled in correctly. Additionally, the URL in the config.php file must also be entered accurately. I recommend placing the sitemap.xml file in the root directory for easier web crawling...
👁 225
(Adaptive Mobile Version) Education & Learning PBootCMS Website Template – Red Education Specialized Website Source Code Download – 0812

(Adaptive Mobile Version) Education & Learning PBootCMS Website Template – Red Education Specialized Website Source Code Download – 0812 Practical Collection pbootcms Template

A specialized PbootCMS website template designed for educational and red-themed education purposes, compatible with both PC and WAP devices. The design features a dignified red color scheme, making it ideal for platforms dedicated to Party history learning, Party building promotion, and patriotic education. This template helps schools or government agencies create dedicated websites for red-themed education initiatives. Template Preview | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extraction Password: www.4s5.cn | Related Articles...
👁 60
Responsive Wood Panel Company – Template 0520

Responsive Wood Panel Company – Template 0520 Practical Collection Yiyou template

An eyoucms responsive website template for wood and panel companies. The design style is professional and practical, able to display wood products, panel series, processing technology and industrial applications. It helps wood companies display their products online and attract furniture and construction customers. Template display Installation instructions Website backend: /login.php Account: admin Password: admin Related articles Yiyou CMS installation FAQ summary Yiyou CM...
👁 36
PHP Website Thumbnail Generator

PHP Website Thumbnail Generator Practical Collection Website source code

How should I put this? It's a piece of source code that I don't use very often, yet can't find when I need it! This is already the nth time I've been searching for this code – I spent a good while looking, and finally, I've found it! That's great! Here's how it looks! Sharing the source code with you: 🔒 Hidden content: Please leave a comment to view the link: https://pan.baidu.com/s/1-IrG92CbRlFsMzgYMHcM0A?pwd=79ga – Extract...
👁 466
(PC+WAP) E-commerce Information Consulting and News Website – pbootCMS Template; Download Source Code for E-commerce News Websites – 0813

(PC+WAP) E-commerce Information Consulting and News Website – pbootCMS Template; Download Source Code for E-commerce News Websites – 0813 Practical Collection pbootcms Template

A PbootCMS template designed for e-commerce information consulting and news websites, supporting both PC and mobile access. Its modern and clean design makes it ideal for aggregating e-commerce industry trends, policy interpretations, and practical operational insights. This template serves as an efficient solution for building e-commerce industry portals or vertical news platforms. Template Display | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extraction Password:...
👁 64