An error is reported when adding a domain name to WeChat h5 payment, "h5 payment domain name needs to provide a complete payment path"

Suppose the domain name to be added is "api.abc.com"

The reason for the failure of the review is that "api.abc.com" cannot be accessed,
so it is necessary to ensure that both abc.com and api.abc.com can be accessed and the content can be seen

Solution:

First, let "abc.com" be accessed normally, which is generally an official website, so this will not be demonstrated

The point is to let "api.abc.com" also visit the official website

Under normal circumstances, our interface access will be in this format, api.abc.com/api/xxx

And the configuration of nginx will be like this:

server
{
    listen 80;
    location / {
      try_files $uri $uri/ /index.php?$query_string;
    }
}

It needs to be changed as follows:

server
{
    listen 80;
    # 当访问api.abc.com/api/xx时,走这里
    # ^~的意思是:一旦匹配成功,则不再查找其他匹配项
    location ^~ /api {
      try_files $uri/ /index.php?$query_string;
    }
    
    # 当访问api.abc.com/xx时,走这里
    # $request_uri 其实就是 /xx
    location  ~ .* {
        resolver 8.8.8.8;
        proxy_pass http://abc.com$request_uri;
    }

	# 以下是错误配置示例1,这样其实也能访问官网,但资源会加载不了,报错404
	# location  ~ .* {
    #    proxy_pass http://abc.com;
    #  }
    
	# 以下是错误配置示例2,这么做会直接返回502
	# location  ~ .* {
    #   proxy_pass http://abc.com$request_uri;
    # }
}

OK~, so the domain name you use for interface requests can also access the official website!

Guess you like

Origin blog.csdn.net/u010775335/article/details/127432479