https://github.com/nginx-modules/ngx_http_cors_filter
:beers: ngx_http_cors_filter_module is a an addon for nginx to dynamic generate cors(Cross-Origin Resource Sharing)
https://github.com/nginx-modules/ngx_http_cors_filter
Last synced: 3 months ago
JSON representation
:beers: ngx_http_cors_filter_module is a an addon for nginx to dynamic generate cors(Cross-Origin Resource Sharing)
- Host: GitHub
- URL: https://github.com/nginx-modules/ngx_http_cors_filter
- Owner: nginx-modules
- Created: 2016-06-24T01:38:51.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2016-06-23T08:58:58.000Z (about 9 years ago)
- Last Synced: 2025-02-07T11:53:49.590Z (5 months ago)
- Language: C
- Size: 8.79 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ngx_http_cors_filter
[](https://travis-ci.org/nginx-lover/ngx_http_cors_filter)[](https://raw.githubusercontent.com/nginx-lover/ngx_http_cors_filter/master/LICENSE)[](https://github.com/nginx-lover/ngx_http_cors_filter/releases)ngx_http_cors_filter_module is a an addon for nginx to dynamic generate cors(Cross-Origin Resource Sharing). Also we can use if to get the the same purpose as following:
```
server {
location / {
if ($http_origin ~ '//(.*?\.example\.com|example\.com)$') {
add_header 'Access-Control-Allow-Origin' "$http_origin";
add_header 'Access-Control-Allow-Credentials' 'true';
}
proxy_pass xx;
}
}
```But you know if is evil and add_header should be in location when it is in if context:(. So use cors, just do this as following:
```
http {
cors //(.*?\.example\.com|example\.com)$;
}or
http {
cors //example\.com$;
cors //.*?\.example\.com$;
}
```Table of Contents
-----------------
* [How-To-Use](#how-to-use)
* [Requirements](#requirements)
* [Direction](#direction)
* [Contributing](#contributing)
* [Author](#author)
* [License](#license)How-To-Use
----------------ngx_http_cors_filter_module add all the response header [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS) header.
For example:```bash
http {
cors //\.cors.com$;
cors //.*\.cors.com$;
}
```Requirements
------------ngx_http_cors_filter requires the following to run:
* [nginx](http://nginx.org/) or other forked version like [openresty](http://openresty.org/)、[tengine](http://tengine.taobao.org/)
Direction
------------* cors: cors codition
Syntax: cors regex
Default: -
Context: main|server|location```
http {
cors //\.cors.com$;
cors //.*\.cors.com$;
}
```* cors_force: force coover reseponse header even if it have already [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS) header
Syntax: cors_force on|off
Default: on
Context: main|server|location```
http {
cors_force on;
cors //\.cors.com$;
cors //.*\.cors.com$;
}
```Contributing
------------To contribute to ngx_http_cors_filter, clone this repo locally and commit your code on a separate branch.
Author
------> GitHub [@detailyang](https://github.com/detailyang)
License
-------
ngx_http_cors_filter is licensed under the [MIT] license.[MIT]: https://github.com/detailyang/ybw/blob/master/licenses/MIT