`
sillycat
  • 浏览: 2486924 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

Nginx Deal with OPTIONS in HTTP Protocol

阅读更多
Nginx Deal with OPTIONS in HTTP Protocol

The idea is to add the OPTIONS in nginx configuration to deal with that.

location / {
      if ($request_method = OPTIONS ) {
          add_header Content-Length 0;
          add_header Content-Type text/plain;
          add_header OPTIONS, GET, HEAD, POST, PUT, DELETE;
          return 200;
      }
      try_files $uri @python_webapp;
}

if ($request_method = OPTIONS ) {
    add_header 'Access-Control-Allow-Origin' '*' always;
    add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, PATCH, OPTIONS';
    add_header 'Access-Control-Allow-Headers' 'Origin,X-Requested-With,Content-Type,Accept,Authorization';
    add_header 'Access-Control-Max-Age' 1728000;
    add_header 'Content-Type' 'text/plain; charset=utf-8';
    add_header 'Content-Length' 0;
    return 200;
}

Django 1.4 Deal with that
https://django.readthedocs.io/en/1.4.X/ref/contrib/csrf.html
https://github.com/adamchainz/django-cors-headers/tree/3b58d638ef08a644dc8ebfc68a7ffdf09835b839/#configuration



References:
https://stackoverflow.com/questions/33548537/error-when-adding-add-header-to-nginx
https://stackoverflow.com/questions/227939/handling-options-request-in-nginx
https://stackoverflow.com/questions/11926908/how-to-respond-to-an-http-options-request




分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics