天天看點

使用nginx代理 解決跨域問題,重定向跨域問題,多次跨域問題

vue是可以直接配置單獨跨域的,可以單獨配置多個,但是後來經理提出需要重定向,二次請求跨域,vue指向不了隻能指向具體一個,這時候用nginx代了解決,

nginx代理核心思想 所有服務都走nginx 所有資源nginx要能通路得到,把不同域變成同域了,就行了

配置代碼:

nginx.conf 裡面的:

#user  nobody;

worker_processes  1;

#error_log  logs/error.log;

#error_log  logs/error.log  notice;

#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

events {

    worker_connections  1024;

}

http {

    include       mime.types;

    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

    server {

        listen      伺服器給nginx的端口 ;

        server_name  伺服器ip;

        location / {

            root   html;

            index  index.html index.htm;

        } 

        error_page   500 502 503 504  /50x.html;

        location = /50x.html {

            root   html;

        }

        location /hsk {

            rewrite  ^/app/(.*)$ /$1 break;

            proxy_pass   http://20318r15r9.iok.la;    

        }

        location /yq {

            rewrite  ^/yq/(.*)$ /$1 break;

            include  uwsgi_params;

            proxy_pass   http://ip:9090;

        }

    }

}

繼續閱讀