编程知识 cdmana.com

Nginx processing front and back end separation cross domain

1. problem
front end vue The project is packaged and deployed in nginx in , The back end is packaged and deployed in tomcat in , Separation of the two , There are cross domain issues .
2. analysis
have access to nginx The agent module of the system deals with cross domain problems . The essence is the front-end direct request nginx, Give Way nginx Forward the request to
tomcat in .
3. server information
domain name :http://test.nginx.com/
Domain name binding ip:http://192.168.1.116
4. Solution
Just configure nginx Of server Of location Add a line to the command proxy_pass Command can . The configuration is as follows :

server {
   listen    80;
   listen [::]:80;
   server_name localhost;
   #charset koi8-r;
   #access_log /var/log/nginx/host.access.log main;
   location / {
    root  /usr/share/nginx/html/antifake;
    index index.html index.htm;
  }
  location /login {
    root  /usr/share/nginx/html/antifake;
    index index.html index.htm;
  }
  location /api {
    proxy_pass  http://192.168.1.116:8081; # Only this line has been added 
  }

restart nginx, Apply the modified configuration .

版权声明
本文为[lyle_ Luo]所创,转载请带上原文链接,感谢
https://cdmana.com/2020/12/20201224102147110q.html

Scroll to Top