美文网首页
Nginx TP5.1请求跨域解决

Nginx TP5.1请求跨域解决

作者: haokeed | 来源:发表于2019-06-25 10:40 被阅读0次

覆盖原来的tp伪静态配置

location / {
    if ($request_method = 'OPTIONS') {
        add_header 'Access-Control-Allow-Origin' '*';
        add_header "Access-Control-Allow-Credentials" "true";
        add_header 'Access-Control-Allow-Methods' 'GET, POST, PATCH, PUT, DELETE'; # 特别注意不能有OPTIONS在里面
        add_header 'Access-Control-Allow-Headers' 'Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-Requested-With';
        add_header 'Access-Control-Max-Age' 1728000;
        add_header 'Content-Type' 'text/plain charset=UTF-8';
        add_header 'Content-Length' 0;
        return 200;
    }
    if ($request_method = 'POST') {
        add_header 'Access-Control-Allow-Origin' '*';
        add_header "Access-Control-Allow-Credentials" "true";
        add_header 'Access-Control-Allow-Methods' 'GET, POST,DELET,PUT,OPTIONS';
        add_header 'Access-Control-Allow-Headers' 'Authorization,Keep-Alive,User-Agent,X-Requested-With,Content-Type';
     }
    if ($request_method = 'GET') {
        add_header 'Access-Control-Allow-Origin' '*';
        add_header "Access-Control-Allow-Credentials" "true";
        add_header 'Access-Control-Allow-Methods' 'GET, POST,DELET,PUT,OPTIONS';
        add_header 'Access-Control-Allow-Headers' 'Authorization,Keep-Alive,User-Agent,X-Requested-With,Content-Type';
     }
    if ($request_method = 'DELETE') {
        add_header 'Access-Control-Allow-Origin' '*';
        add_header "Access-Control-Allow-Credentials" "true";
        add_header 'Access-Control-Allow-Methods' 'GET, POST,DELET,PUT,OPTIONS';
        add_header 'Access-Control-Allow-Headers' 'Authorization,Keep-Alive,User-Agent,X-Requested-With,Content-Type';
     }
    if ($request_method = 'put') {
        add_header 'Access-Control-Allow-Origin' '*';
        add_header "Access-Control-Allow-Credentials" "true";
        add_header 'Access-Control-Allow-Methods' 'GET, POST,DELET,PUT,OPTIONS';
        add_header 'Access-Control-Allow-Headers' 'Authorization,Keep-Alive,User-Agent,X-Requested-With,Content-Type';
     }
    if (!-e $request_filename) {
        rewrite  ^(.*)$  /index.php?s=/$1  last;
    }

    index  index.php;
    autoindex  off;
}

相关文章

  • Nginx TP5.1请求跨域解决

    覆盖原来的tp伪静态配置

  • [mark]九种跨域方式实现原理

    前端如何使用proxyTable和nginx解决跨域问题 前言 前后端数据交互经常会碰到请求跨域,什么是跨域,以及...

  • 跨域方法集锦

    什么叫跨域跨域解决方法:1.cors(简单请求、非简单请求)2.jsonp3.new Image()4.nginx...

  • 跨域

    ??JSONP只能解决GET请求跨域,不能解决POST请求跨域问题,XHR2可以解决GET,POST方式的请求跨域...

  • Nginx跨域请求设置

    Nginx跨域请求设置 开发环境中,前后端分离开发时,经常会有跨域请求的问题出现,Nginx可以设置如下: 说明:...

  • 浏览器跨域的那些事

    整理中 目标: 了解跨域 解决跨域 服务器配置跨域(java, nginx) 前端调试时配置解决跨域 一、什么是跨...

  • Nginx配置跨域请求

    Nginx配置跨域请求 背景:图片存于服务器,使用Nginx进行转发,前端使用某组件对图片进行裁剪时,请求跨域了,...

  • Nginx跨域

    Nginx解决跨域问题(CORS) CORS(Cross-Origin Resource Sharing) 跨域资...

  • nginx配置跨域请求

    转载 Nginx配置跨域请求 Access-Control-Allow-Origin 当出现403跨域错误的时候 ...

  • 跨域问题,解决方案

    跨域问题,解决方案 - Nginx反向代理跨域问题,解决方案 - CORS方案此为原作者的链接:跨域问题,解决之道

网友评论

      本文标题:Nginx TP5.1请求跨域解决

      本文链接:https://www.haomeiwen.com/subject/rqttcctx.html