Giter Site home page Giter Site logo

rekgrpth / ngx_http_cors_filter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nginx-modules/ngx_http_cors_filter

1.0 2.0 0.0 15 KB

:beers: ngx_http_cors_filter_module is a an addon for nginx to dynamic generate cors(Cross-Origin Resource Sharing)

Makefile 0.87% C 83.28% Perl 15.86%

ngx_http_cors_filter's Introduction

ngx_http_cors_filter

Branch masterBuildGitHub licenserelease

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

ngx_http_cors_filter_module add all the response header CORS header. For example:

http {
    cors //\.cors.com$;
    cors //.*\.cors.com$;
    cors_force on;
    cors_expose "X-My-Custom-Header, X-Another-Custom-Header";
    cors_age "360000";
    cors_method "GET, POST, OPTIONS";
    cors_header "Origin";
}

Requirements

ngx_http_cors_filter requires the following to run:

Direction

  • cors: cors codition
    Syntax: cors regex
    Default: -
    Context: main|server|location
http {
    cors //\.cors.com$;
    cors //.*\.cors.com$;
}
  • cors_force: force cover reseponse header even if it have already CORS header
    Syntax: cors_force on|off
    Default: on
    Context: main|server|location
http {
    cors_force on;
    cors //\.cors.com$;
    cors //.*\.cors.com$;
}
  • cors_expose: add reseponse header Access-Control-Expose-Headers: X-My-Custom-Header, X-Another-Custom-Header

Syntax: cors_expose string
Default: null
Context: main|server|location

http {
    cors_expose "X-My-Custom-Header, X-Another-Custom-Header";
}
  • cors_age: add reseponse header Access-Control-Max-Age: 3600

Syntax: cors_age string
Default: 3600
Context: main|server|location

http {
    cors_age "99999999";
}
  • cors_method: add reseponse header Access-Control-Allow-Methods: <method>[, <method>]*

Syntax: cors_method string
Default: null
Context: main|server|location

http {
    cors_method "POST, GET, OPTIONS";
}
  • cors_header: add reseponse header Access-Control-Allow-Headers: X-PINGOTHER, Content-Type

Syntax: cors_header string
Default: null
Context: main|server|location

http {
    cors_header "X-PINGOTHER, Content-Type";
}

Contributing

To contribute to ngx_http_cors_filter, clone this repo locally and commit your code on a separate branch.

Author

GitHub @detailyang

License

ngx_http_cors_filter is licensed under the MIT license.

ngx_http_cors_filter's People

Contributors

detailyang avatar

Stargazers

Georgy Shelkovy avatar

Watchers

James Cloos avatar Georgy Shelkovy avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.