What do I do if a 404 error occurs when I use a browser or the cURL tool to access a function?
A 404 error when invoking an HTTP function through the default proxy URL is caused by a path mismatch. The Function Compute proxy URL includes a prefix (/2016-08-15/proxy/<serviceName>/<functionName>) that is forwarded to your application. If your app registers a short route like /test, it never receives a path it can match and returns 404.
For example, if your Flask app registers:
@app.route('/test', methods=['POST', 'GET'])
def test():...and you call the function using the default proxy URL:
https://164901546557****.cn-hangzhou.fc.aliyuncs.com/2016-08-15/proxy/CustomDemo/func-http/testFlask receives /2016-08-15/proxy/CustomDemo/func-http/test and returns 404 because it only knows /test.
Choose a fix based on your situation:
| Situation | Recommended fix |
|---|---|
| Testing the function quickly | Use the FC-assigned subdomain URL |
| Calling via cURL without changing the URL | Add the x-fc-invocation-target header |
| Production traffic | Bind a custom domain name |
| Cannot change the URL or add headers | Update your route to match the proxy URL |
Use the FC-assigned subdomain URL
Function Compute assigns each HTTP trigger a subdomain URL that routes requests directly to your function without the proxy prefix. Your app receives only the path suffix (for example, /test), which matches your registered routes.
Subdomain URL format:
https://<subdomain>.<region_id>.fcapp.run/[action?queries]Example:
https://funcname-svcname-khljsjksld.cn-shanghai.fcapp.run/action?hello=worldTo find your subdomain URL, see Step 3: Test the function.
This is the simplest fix for testing. For production traffic, bind a custom domain name instead.
Add the x-fc-invocation-target header
Add the x-fc-invocation-target request header to your cURL command. Function Compute uses this header to identify which function to invoke, so you can call the function using just the path your app registers — without including the proxy prefix in the URL.
Request header format:
x-fc-invocation-target: 2016-08-15/proxy/<serviceName>/<functionName>Command syntax:
curl -v -H "x-fc-invocation-target: 2016-08-15/proxy/$ServiceName/$functionName" \
https://<account_id>.<region_id>.fc.aliyuncs.com/$pathExample using the CustomDemo service and func-http function:
curl -v -H "x-fc-invocation-target: 2016-08-15/proxy/CustomDemo/func-http" \
https://164901546557****.cn-hangzhou.fc.aliyuncs.com/testBind a custom domain name
Bind a custom domain name to your function and configure a route mapping. Requests to your domain are forwarded to the function with only the path suffix, matching your app's registered routes.
After binding example.com to your function with route path /test, run:
curl -v https://example.com/testThe path in your request must match the path configured when you bind the custom domain. For configuration steps, see Configure a custom domain name. For path matching behavior, see Route matching rules.
Update your route to match the proxy URL
Register the full proxy path — including the API version, service name, and function name — as the route in your app. This lets the default proxy URL work without changing the URL or adding headers.
Update your route from:
@app.route('/test', methods=['POST', 'GET'])
def test():To:
@app.route('/2016-08-15/proxy/CustomDemo/func-http/test', methods=['POST', 'GET'])
def test():After deploying the updated function, the original cURL command works:
curl -v https://164901546557****.cn-hangzhou.fc.aliyuncs.com/2016-08-15/proxy/CustomDemo/func-http/testThis approach ties your route definitions to the Function Compute proxy URL structure. Use it only when you cannot modify the access URL or add request headers.