1

I have two servers.

Server 1: 185.185.xxx.xxx (this is the main server with domain mydomain.com)

Server 2: 176.28.xxx.xxx

On the first server I added A zone

A   cdn    176.28.xxx.xxx

When I type cdn.mydomain.com this link will open 176.28.xxx.xxx (I'm already set host) And this is working fine.

WHAT I NEED

When user type mydomain.com/cdn I need to open same as cdn.mydomain.com (on second server)

example

user type: mydomain.com/cdn/myphotos.zip

need to open: cdn.mydomain.com/myphotos.zip

How to set this?

I'm trying, but no luck. I'm have Ubuntu and Nginx. No Apache. I'm need config for ngnix. Can anybody help me? Thanks

1 Answer 1

1

You can use a map to capture the path relative to the cdn directory on Server 1 then define a variable that points to the same file at the root of Server 2.

Maps are evaluated early in the nginx cycle and are a good place to use regular expressions.

map $uri $cdn_uri {
    ~^/cdn/(?<path>.+) $scheme://cdn.mydomain.com/$path;
}

If the $cdn_uri variable is set, redirect to it on Server 2.

server {
    # Server 1

    if ($cdn_uri) {
        return 301 $cdn_uri;
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.