首页 Function Compute Function Compute FAQ Code development Custom Container FAQ What do I do if a 404 error occurs when I use a browser or the cURL tool to access a function?

What do I do if a 404 error occurs when I use a browser or the cURL tool to access a function?

更新时间: 2026-04-01 08:44:14

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/test

Flask receives /2016-08-15/proxy/CustomDemo/func-http/test and returns 404 because it only knows /test.

Choose a fix based on your situation:

SituationRecommended fix
Testing the function quicklyUse the FC-assigned subdomain URL
Calling via cURL without changing the URLAdd the x-fc-invocation-target header
Production trafficBind a custom domain name
Cannot change the URL or add headersUpdate 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=world

To find your subdomain URL, see Step 3: Test the function.

Note

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/$path

Example 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/test

Bind 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/test
Important

The 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/test
Note

This 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.

上一篇: 502 error: "Process exited unexpectedly before completing request" 下一篇: Can I modify the limit on the body size of an HTTP request?
阿里云首页 函数计算 相关技术圈