03——博客项目之登陆05

1.和前端联调

[2.演示]

1.和前端联调

  • 登陆功能依赖cookie,必须用浏览器来联调
  • cookie 跨域不共享,前端和server端必须同域
  • 需要用到 nginx 做代理,让前后端同域

前端文件目录:

在这里插入图片描述
1.开启http服务

安装 http服务,开启8001端口

npm install http-server -g
http-server -p 8001

访问http:localhost
由于服务器端口是800端口,而我们的端口是8001,所以会404,况且cookie跨域也不共享。解决方案是用nginx进行联调。

2.使用nginx联调

我的nginx目录:

C:\nginx-1.19.0\conf

nginx.conf 配置

 server {
          listen 8080;
          location / {
              proxy_pass  http://localhost:8001;
          }
          location /api/ {
	proxy_pass http://localhost:8000;
                proxy_set_header Host $host;
          }
     }

开启nginx代理

C:\Users\way liu>cd C:\nginx-1.19.0
C:\nginx-1.19.0>nginx -v
nginx version: nginx/1.19.0
C:\nginx-1.19.0>nginx -t
nginx: the configuration file C:\nginx-1.19.0/conf/nginx.conf syntax is ok
nginx: configuration file C:\nginx-1.19.0/conf/nginx.conf test is successful

C:\nginx-1.19.0>start nginx
  1. nginx -v 查看nginx版本
  2. nginx -t 检查nginx配置语法
  3. start nginx 开启nginx
  4. 参考 https://www.cnblogs.com/yang-2018/p/11418506.html

2.演示

1.http://127.0.0.1:8080/index.html

在这里插入图片描述
2. 登陆与管理
http://127.0.0.1:8080/login.html

在这里插入图片描述
在这里插入图片描述
3.点击编辑

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值