使用Nginx代理配置解决跨域问题

使用Nginx代理配置解决跨域问题##

下载nginx

下载地址

配置nginx

在nginx.conf文件中找到server代码块中做如下配置,注意,’/'不能少。其中前端服务的配置尽量不要加后缀,容易出现获取不到静态资源数据的bug。访问的时候通过访问 localhost:8888 进入前端服务器 ,请求接口的地址时把之前的 ip:port/改写成 localhost:8888/api/

	server {
        listen       8888;
        server_name  localhost;
       #接口服务
        location /api/ {
			 proxy_pass http://ip:port/;
        }
      #前端服务
		 location /{
			 proxy_pass http://www.baidu.com/;
        }
        
 	   error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

Nginx默认请求体是1M 假如涉及到文件的上传,是不够的 ,需要配置文件上传的限制
client_max_body_size 2048M;

		client_header_timeout    1m;

		client_body_timeout      1m;

		proxy_connect_timeout     120s;

		proxy_read_timeout      1m;

		proxy_send_timeout      1m;

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值