zoukankan      html  css  js  c++  java
  • Nginx 跨域配置

    server {
        listen 80;
    
        server_name pre-mobile-api.yudhabhakti.co.id;
        access_log /data/logs/nginx/access.pre-mobile-api.yudhabhakti.co.id.http.log main;
        error_log /data/logs/nginx/error.pre-mobile-api.yudhabhakti.co.id.http.log warn;
    
        location / {
            if ($http_origin !~ '.yudhabhakti.co.id$') {
                 return 403;
            }
            if ($request_method = 'OPTIONS') {
                add_header 'Access-Control-Allow-Origin' $http_origin;
                add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
                add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
                add_header 'Access-Control-Max-Age' 1728000;
                add_header 'Content-Type' 'text/plain; charset=utf-8';
                add_header 'Content-Length' 0;
                return 204;
            }
            if ($request_method = 'POST') {
                add_header 'Access-Control-Allow-Origin' $http_origin;
                add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
                add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
                add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
            }   
            if ($request_method = 'GET') {
                add_header 'Access-Control-Allow-Origin' $http_origin;
                add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
                add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
                add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
            }
            proxy_pass http://gateway;
        }
    }
    

      

  • 相关阅读:
    Hbuilder——报错The keyword 'export' is reserved
    控制器里路径变量的使用
    Spring 控制器重定向
    Spring A 标签链接使用
    Spring switch的使用
    thymeleaf如何遍历数据 each循环的使用
    spring 机制 扫描包
    Spring分层次建包
    什么是MVC模型
    如何运行spring boot 工程
  • 原文地址:https://www.cnblogs.com/NGU-PX/p/14151402.html
Copyright © 2011-2022 走看看