nginx反向代理node,解决前后端跨域问题

nginx代理某一端口

server {
  listen 80;
  server_name www.zhangwenzong.cn;

  access_log  /home/zhangwenzong/pb.haolinks.com_nginx.log combined;
  index index.html index.htm index.php;
  #include /usr/local/nginx/conf/rewrite/none.conf;
  root /data/wwwroot/postback;

  location / {
      proxy_pass http://127.0.0.1:8080/;
    }
}

nginx代理node3000端口

二级域名还需要在域名管理进项域名解析添加一个二级域名
下面的还涉及到访问转发,解决跨域问题

server {
  listen 80;
  server_name nodevue.zhangwenzong.cn;
  access_log  /home/zhangwenzong/pb.haolinks.com_nginx.log combined;
  index index.html index.htm index.php;
  #include /usr/local/nginx/conf/rewrite/none.conf;
  root /data/wwwroot/postback;

  location / {
      proxy_set_header X-Real-IP  $remote_addr;
      proxy_pass http://127.0.0.1:3000/;
    }
  location /users/ {
      proxy_pass http://127.0.0.1:3000/users;
    }
  location /cart/ {
      proxy_pass http://127.0.0.1:3000/cart;
    }
  location /goods/* {
      proxy_pass http://127.0.0.1:3000/goods;
    }
}
发布了57 篇原创文章 · 获赞 76 · 访问量 6万+

猜你喜欢

转载自blog.csdn.net/zhang5207892/article/details/78934141