Home  >  Article  >  Backend Development  >  How does nginx perform different operations based on the response of the proxy server?

How does nginx perform different operations based on the response of the proxy server?

WBOY
WBOYOriginal
2016-12-01 00:57:101076browse

There is a problem. Some pictures exist on the local server, and some exist on third-party servers.
And the picture names are similar ~ it’s hard to distinguish ~
So I want to configure a proxy. If it can’t be found on the local server, proxy it to the third-party server. Third-party server.
How to configure this nginx?


Final solution:

<code>location /{
        root  xxxxx;
        index index.html;
        if (!-e $request_filename) {
            proxy_pass yyyyyy;
        }
    }</code>

Reply content:

There is a problem. Some pictures exist on the local server, and some exist on third-party servers.
And the picture names are similar ~ it’s hard to distinguish ~
So I want to configure a proxy. If it can’t be found on the local server, proxy it to the third-party server. Third-party server.
How to configure this nginx?


Final solution:

<code>location /{
        root  xxxxx;
        index index.html;
        if (!-e $request_filename) {
            proxy_pass yyyyyy;
        }
    }</code>

Error redirect

location /{

<code>error_page   404   @test;</code>

}

location @test{

<code>proxy_pass http://upstreamName;</code>

}

Finally solved this~

<code>location /{
        root xxxx;
        index index.html;
        if (!-e $request_filename) {
            proxy_pass yyyyyyyyy;
        }
    }</code>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn