鍍金池/ 問答/人工智能  Java  Linux  HTML/ nginx如何配置才可以讓同一域名不同端口的前后端進(jìn)行交互。

nginx如何配置才可以讓同一域名不同端口的前后端進(jìn)行交互。

現(xiàn)在我的項(xiàng)目的前端是react,后端是ssm,前端在localhost:3000 ,后端在localhost:8080,
也就是localhost:3000的請求如何轉(zhuǎn)到localhost:8080,
如何正確設(shè)置nginx的location
以下是我的location配置:

   server { 
   listen 80; 
   
   server_name  localhost;

    #charset koi8-r;

    #access_log  logs/host.access.log  main;

    location / {
        root   html;
        index  index.html index.htm;  
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    location ~ \.json$ {
        proxy_pass http://localhost:8080;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

請求大神詳細(xì)解答,比較急!!
回答
編輯回答
老梗

api為你的請求固定前綴,自行更換

location /api {
  proxy_pass  http://localhost:8080/api;
}

具體可參考 https://www.thinktxt.com/ngin...

2018年3月22日 05:59
編輯回答
陌顏

微服務(wù)Api網(wǎng)關(guān)框架http://www.roncoo.com/course/...

2018年3月23日 14:48
編輯回答
挽青絲

設(shè)置反向代理

2018年1月3日 12:06