apisix伺服静态文件的方法
nginx_config:
http_configuration_snippet: |
#ssl_dhparam /etc/ssl/certs/dhparam.pem;
server{
listen 45651;
server_name _;
access_log off;
location / {
root /usr/local/apisix/conf;
index index.html index.htm;
autoindex on;
autoindex_exact_size on;
autoindex_localtime on;
types {
text/plain yaml;
text/plain md;
text/plain yml;
text/plain conf;
text/plain properties;
text/plain service;
text/plain sh;
text/plain sed;
}
}
}
StripPrefix
比如,请求/name/bar/foo,去除掉前面两个前缀之后,最后转发到目标服务的路径为/foo
StripPrefix=2
^/([^/]+)/([^/]+)/(.*)$
/${3}
StripPrefix=1
^/([^/]+)/(.*)$
/${2}
^/nexus(/|$)(.*)
/$2
{
"name": "httpbin",
"plugins": {
"proxy-rewrite": {
"use_real_request_uri_unsafe": false,
"regex_uri": [
"^/([^/]+)/(.*)$",
"/${2}"
]
}
},
"priority": 10,
"status": 1,
"upstream": {
"hash_on": "vars",
"nodes": [
{
"host": "127.0.0.1",
"port": 9991,
"weight": 1
}
],
"pass_host": "pass",
"scheme": "http",
"timeout": {
"connect": 6,
"send": 6,
"read": 6
},
"type": "roundrobin"
},
"uri": "/httpbin/*"
}
PrefixPath
比如:请求/hello,最后转发到目标服务的路径变为/mypath/hello
{
"name": "minio-test",
"plugins": {
"proxy-rewrite": {
"use_real_request_uri_unsafe": false,
"regex_uri": [
"^/(.*)$",
"/test/${1}"
]
}
},
"priority": 10,
"status": 1,
"upstream": {
"hash_on": "vars",
"nodes": [
{
"host": "127.0.0.1",
"port": 19000,
"weight": 1
}
],
"pass_host": "pass",
"scheme": "http",
"timeout": {
"connect": 6,
"send": 6,
"read": 6
},
"type": "roundrobin"
},
"uri": "/*"
}
- 标签 apisix