Question

Would anyone have the code to put into an Nginx block somewhere for the following scenario.

I have our site going through Cloudflare (url.com) but they don't support uploads of more than 150mb, we have uploads up to 300mb. Their solution for this it to create a sub domain (upload.url.com) which isn't Cloudflare enabled and use that for uploads. Ive done this, no problem and hardcoded the links to the upload page to go via the upload URL. The problem is now, where my site has links which are just "/page" its going via upload.url.com/page, would there be a way in Nginx block to set it so anything going to upload.url.com just works on the upload pages I want it to go to and if they click back to any other part of the site it will make sure it loads up that page via "url.com"?

Was it helpful?

Solution

server {
    server_name "upload.example.com";

    location ^~ /page {
        return 301 http://example.com$uri;
    }
}

Or if all your upload pages can be identified via a specific portion within the URL.

server {
    server_name "upload.example.com";

    location / {
        location ~* "^(?!.*?upload).*$" {
            return 301 http://example.com$uri;
        }
    }
}

Or if you only have a single valid location.

server {
    server_name "upload.example.com";

    location = /upload-script {
        # Code to process upload
    }

    # Redirect anything else!
    location / {
        return 301 http://example.com$uri;
    }
}

OTHER TIPS

I'm not sure I got what you want correctly, you want to redirect any URI that isn't root to the main domain, try this

server {
  server_name upload.example.com;
  location = / {
    #pass to the upload script;
  }
  location / {
    # redirect to the main domain
    return 301 http://example.com$request_uri$is_args$query_string;
  }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top