当前位置: 首页 > news >正文

若依前后端分离版运行教程、打包教程、部署教程

  1. 后端打包教程

注意:需要先运行redis

2、前端运行教程

2.1安装依赖

2.2运行

打开浏览器查看,地址:http://localhost:80

3、前端打包教程

3.1打包

3.2运行打包好的文件,先找到打包好的文件

这是nginx的文件结构

将打包好的文件放到html目录下

这是index.html文件所在目录

配置nginx代理规则

启动nginx

启动后进入浏览器查看,地址:http://localhost:80/

以下是重启nginx的命令:nginx -s reload

以下是重启nginx的命令:nginx -s reload
nginx  启动
nginx -s stop  停止
nginx -s quit  安全退出
nginx -s reload  重新加载配置文件  如果我们修改了配置文件,就需要重新加载。
ps aux|grep nginx  查看nginx进程

接口异常是因为请求发送不到后端

发现向后端请求  “生成验证码”  时发送到了http://localhost/prod-api/captchaImage

而后端端口是8080,本机地址是localhost,也可以用127.0.0.1表示

按ctrl+shift+f键,找到生成二维码的接口

发现这个控制器类没有配置访问地址,只有方法配置了访问地址,所以想要进入该方法,就应该发请求到localhost:80/captchaImage

所以前端应该要配置nginx代理规则:将所有以/prod-api/开头的请求全部代理到http://127.0.0.1:8080/

比如:http://localhost/prod-api/captchaImage会代理到,会变成http://localhost/captchaImage

个人猜想:应该是把http://127.0.0.1:8080/prod-api/改成了http://127.0.0.1:8080/,后面的内容没变

配置代码如下


#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;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80; #监听80端口
        server_name  localhost; #服务器的ipv4地址

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / { #默认首页,访问/时,返回html/dist目录下的index.html(即访问localhost:80/时,返回html/dist目录下的index.html)
            root   html/dist;
            index  index.html index.htm;
            try_files $uri $uri/ /index.html; #加上这一行,页面刷新就不会出现404
        }
        location /prod-api/ { #表示当请求的路径以 "/prod-api/" 开头时,应用后续的配置规则。
            proxy_set_header Host $http_host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header REMOTE-HOST $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass http://127.0.0.1:8080/; #表示将请求转发到本地的 127.0.0.1:8080 地址。
        }
        #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 ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # 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;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

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


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

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

}

重启nginx后刷新浏览器,成功了


文章转载自:

http://3eoTUA6p.xjbtb.cn
http://0bDjy9ui.xjbtb.cn
http://PChIX1Yf.xjbtb.cn
http://QvgaiouE.xjbtb.cn
http://ydHOSaOj.xjbtb.cn
http://i0s3bfuu.xjbtb.cn
http://FRybw90p.xjbtb.cn
http://oYR8Yriw.xjbtb.cn
http://7hV0vYfF.xjbtb.cn
http://SnnYi45v.xjbtb.cn
http://vI3ab2nx.xjbtb.cn
http://uoZ6ZJaR.xjbtb.cn
http://32R479hl.xjbtb.cn
http://3Z9doUeE.xjbtb.cn
http://xN0U8tXS.xjbtb.cn
http://QXekcH6c.xjbtb.cn
http://viwoNaDX.xjbtb.cn
http://UlurTsMV.xjbtb.cn
http://Zt7wJLW5.xjbtb.cn
http://erKbNyAP.xjbtb.cn
http://llyfvTCL.xjbtb.cn
http://baYaGMB7.xjbtb.cn
http://QVMRyM83.xjbtb.cn
http://fZiD1gME.xjbtb.cn
http://CEtPskV1.xjbtb.cn
http://iYkm9cN3.xjbtb.cn
http://H8pNJ2Fe.xjbtb.cn
http://NyTqApOr.xjbtb.cn
http://03DMECJC.xjbtb.cn
http://rK5XwVG9.xjbtb.cn
http://www.dtcms.com/a/128625.html

相关文章:

  • Linux-内核驱动
  • Window 10使用WSL2搭建Linux版Android Studio应用开发环境
  • Redis集群模式学习
  • Kubernetes nodeName Manual Scheduling practice (K8S节点名称绑定以及手工调度)
  • 【高性能缓存Redis_中间件】一、快速上手redis缓存中间件
  • 大型语言模型中的工具调用(Function Calling)技术详解
  • 鸿蒙开发05评论案例分析
  • 基于 Streamlit 的 PDF 编辑器
  • 1558 找素数
  • vue模拟扑克效果
  • AdamW 是 Adam 优化算法的改进版本; warmup_steps:学习率热身的步数
  • Python中NumPy的索引和切片
  • vue 前端遇到问题 样式不展示
  • 常见MQ及类MQ对比:Redis Stream、Redis Pub/Sub、RocketMQ、Kafka 和 RabbitMQ
  • redis大key排查指南
  • Redis 主从复制+哨兵模式+集群部署(含节点扩容)
  • IDEA202403 常用设置【持续更新】
  • 电梯广告江湖的终局:分众 “吃掉” 新潮,是救赎还是迷途?
  • mac 解压 nsz 文件
  • Agent2Agent (A2A)
  • 激光雷达点云动态目标剔除算法
  • 【提示词】001-命令行大师
  • php伪协议
  • Springboot项目正常启动,访问资源却出现404错误如何解决?
  • 基于疾风大模型的新能源电力交易决策系统:方法、实现与案例分析
  • Docker日志查看与资源监控指令全解:从基础到高阶运维实践
  • python【标准库】multiprocessing
  • Centos7.9 升级内核,安装RTX5880驱动
  • 【2】k8s集群管理系列--包应用管理器之helm(Chart语法深入应用)
  • 149页研读——华为基于IPD全过程研发质量管理【附全文阅读】