咏竹莉
where there is a will,there is a way

nginx 配置

events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  localhost;
        location / {
            proxy_pass  http://localhost:8887;
            add_header  Access-Control-Allow-Origin *;
        }
    }
}

利用nginx跨域的关键在配置文件设置server项,然后设置其中的location 属性,proxy_pass: 需要代理的服务器地址,add_header: 给响应报文中添加首部字段,例如Access-Control-Allow-Orign设置为*, 即允许所有的请求资源。

 

 

反向代理

我们将请求发送到服务器,然后服务器对我们的请求进行转发,我们只需要和代理服务器进行通信,对用客户端来说,是感知不到服务器的。

反向代理隐藏了真实的服务端,我们只需要知道反向代理服务器是谁

正向代理隐藏真实客户端,反向代理隐藏真实服务端

posted on 2021-04-09 14:30  咏竹莉  阅读(70)  评论(0)    收藏  举报