zoukankan      html  css  js  c++  java
  • 在Linux环境下解决Nginx跨域问题

    Nginx解决跨域问题

    跨域问题

    当我们在同一个站点请求时,是不存在什么问题的,但是当我们从一个站点向另外一个站点访问的时候就会出现跨域问题

    解决跨域问题(CORS跨域资源共享)

    1.Cross-Origin Resource Sharing(跨域资源共享)
    2.允许浏览器向跨Origin的服务器发起js请求获取响应
    3.Jsonp、SpringBoot Cors、Nginx

    Nginx的解决方案

    在nginx.conf中配置文件中的server指令块下面配置以下内容,之后就可以解决跨域问题了

    server {
            listen       80;
            server_name  localhost;
    
            # 允许跨域请求的域,*代表所有
            add_header 'Access-Control-Allow-Origin' *;
            # 允许带上cookie请求
            add_header 'Access-Control-Allow-Credentials' 'true';
            # 允许请求的方法,比如 GET/POST/PUT/DELETE
            add_header 'Access-Control-Allow-Method' *;
            # 允许请求的header
            add_header 'Access-Control-Allow-Headers' *;
    
            location / {
                root   html;
                index  index.html index.htm;
            }
        }
  • 相关阅读:
    Bean生命周期
    Bean的作用域
    神经网络训练中,傻傻分不清Epoch、Batch Size和迭代
    jQuery中选择器有哪几种
    数据库的事务机制
    多线程面试题
    HTTP请求报文和HTTP响应报文
    linux tomcat单机部署多应用
    flexbox预习
    作业
  • 原文地址:https://www.cnblogs.com/banma/p/14421409.html
Copyright © 2011-2022 走看看