2019-10-31 09:27:28 +08:00
<!--
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
-->
2019-11-24 21:15:39 +08:00
[Chinese ](proxy-rewrite-cn.md )
# Summary
- [**Name** ](#name )
- [**Attributes** ](#attributes )
- [**How To Enable** ](#how-to-enable )
- [**Test Plugin** ](#test-plugin )
- [**Disable Plugin** ](#disable-plugin )
## Name
2019-09-27 15:14:49 +08:00
upstream proxy info rewrite plugin.
2019-11-24 21:15:39 +08:00
## Attributes
|Name | Requirement |Description|
2019-09-27 15:14:49 +08:00
|------- |-----|------|
2019-11-24 21:15:39 +08:00
|scheme |optional| Upstream new `schema` forwarding protocol,options can be `http` or `https` ,default `http` .|
|uri |optional| Upstream new `uri` forwarding address.|
|host |optional| Upstream new `host` forwarding address, example `iresty.com` . |
|enable_websocket|optional| enable `websocket` (boolean), default `false` .|
|headers |optional| Forward to the new `headers` of the upstream, can set up multiple. If it exists, will rewrite the header, otherwise will add the header. You can set the corresponding value to an empty string to remove a header.|
2019-09-27 15:14:49 +08:00
2019-11-24 21:15:39 +08:00
## How To Enable
2019-09-27 15:14:49 +08:00
Here's an example, enable the `proxy rewrite` plugin on the specified route:
```shell
curl http://127.0.0.1:9080/apisix/admin/routes/1 -X PUT -d '
{
"methods": ["GET"],
"uri": "/test/index.html",
"plugins": {
"proxy-rewrite": {
"uri": "/test/home.html",
"scheme": "http",
"host": "iresty.com",
2019-10-09 15:10:16 +08:00
"enable_websocket": true,
"headers": {
"X-Api-Version": "v1",
2019-10-15 16:06:28 +08:00
"X-Api-Engine": "apisix",
"X-Api-useless": ""
2019-10-09 15:10:16 +08:00
}
2019-09-27 15:14:49 +08:00
}
},
"upstream": {
"type": "roundrobin",
"nodes": {
"127.0.0.1:80": 1
}
}
}'
```
2019-11-24 21:15:39 +08:00
## Test Plugin
2019-09-27 15:14:49 +08:00
Testing based on the above examples :
```shell
curl -X GET http://127.0.0.1:9080/test/index.html
```
Send the request and see upstream `access.log', if the output information is consistent with the configuration :
```
127.0.0.1 - [26/Sep/2019:10:52:20 +0800] iresty.com GET /test/home.html HTTP/1.1 200 38 - curl/7.29.0 - 0.000 199 107
```
This means that the `proxy rewrite` plugin is in effect.
2019-11-24 21:15:39 +08:00
## Disable Plugin
2019-09-27 15:14:49 +08:00
When you want to disable the `proxy rewrite` plugin, it is very simple,
you can delete the corresponding json configuration in the plugin configuration,
no need to restart the service, it will take effect immediately :
```shell
curl http://127.0.0.1:9080/apisix/admin/routes/1 -X PUT -d '
{
"methods": ["GET"],
"uri": "/test/index.html",
"plugins": {},
"upstream": {
"type": "roundrobin",
"nodes": {
"127.0.0.1:80": 1
}
}
}'
```
The `proxy rewrite` plugin has been disabled now. It works for other plugins.