在windows服务器上部署一个单机项目以及前后端分离项目

简介: 在windows服务器上部署一个单机项目以及前后端分离项目

一. 单机项目在windows服务器上的部署

注意:无论是单机项目还是前后端分离项目,在部署前要确保有sql文件和war文件,并在本机上进行测试确保无误,再在服务器上完成部署。

1.1 在本机上测试项目无误

1.1.1 在数据库中测试sql文件没问题

新建一个数据库,将要用到的单机项目的sql文件运行,显示0错误则表示该脚本无误。

1.1.2 在tomcat中测试war文件无误

将单机项目的war文件放入到tomcat的webapps文件夹下,然后返回到bin目录,运行bin文件夹下的startup.bat,黑窗口运行结束则代表没问题。

1.1.3 测试完成后,进入浏览器运行单机项目确保无误

注意:war文件测试后,黑窗口先不要关闭,否则项目运行不了

1.2 在windows服务器中运行项目

\\+服务器ip地址  ,进入服务器创建的文件夹,将项目压缩包导入。

然后在windows服务器上将项目提取出来,如果是中文目录,将其改为非中文目录,防止后面出错。

在本机的navicat中,记得在远程连接的数据库中导入sql文件

在windows服务器上,将war文件同样放入到tomcat下的webapps文件夹中

然后运行bin文件夹下的startup.bat

这里要注意,项目配置文件中的数据库密码要与本机数据库的一致

然后再浏览器上运行该项目

二. 前后端分离项目在服务器上的部署

2.1 在本机上进行测试

与单机项目一样的进行war文件的测试,将war文件放入webapps文件夹中,然后运行bin文件夹下的statrup.bat

后端测试成功:

这里会显示错误是因为开了jwt认证

前端测试

在spa项目目录下输入cmd打开黑窗口,输入npm run dev 运行该项目

测试成功:

2.2 在服务器上进行项目部署

同样的,先将压缩包提取,然后将war文件放入到tomcat的webapps文件夹下,然后运行bin文件夹下的startup.bat

在运行sql文件前,可以先在解压出来的项目中,确定端口号和数据库

2.3 nodejs环境搭建

将nodejs压缩包提取,再解压后的目录建立两个文件夹node_global和node_cache

目录说明:

       node_global : npm全局安装位置

       node_cache : npm缓存路径

配置环境变量

新建NODE_HOME

编辑path ;%NODE_HOME%;%NODE_HOME%\node_global;

查看环境变量

win+r➡cmd➡node -v

配置npm全局模块路径和cache默认安装位置

打开cmd,分开执行如下命令:

     npm config set cache "C:\software\node-v18.16.1-win-x64\node-v18.16.1-win-x64\node_global"

     npm config set prefix "C:\software\node-v18.16.1-win-x64\node-v18.16.1-win-x64\node_cache"

设置淘宝源

npm config set registry https://registry.npm.taobao.org/

2.4 项目部署

这里接下来会出现一个问题,在本机上服务器中部署的项目应用访问不了,在服务器内部是可以访问的。

原因是nodejs中spa项目做了限制,这个限制类似于mysql中localhost设置,没有被解析成ip。

解决方案1:

在服务器中利用nginx架设反向代理服务器,用80去代理81

在nginx文件中找到nginx.conf 文件,将文件中的 location 进行修改,将端口代理访问

location / {

           #root   html;

       proxy_pass   http://localhost:8081;

           index  index.html index.htm;

       }

修改后重启 nginx.exe -s reload

nginx.conf

#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;
        server_name  localhost;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        location / {
            proxy_pass   http://localhost:8081;
        }
        #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;
    #    }
    #}
}

解决方案2:

在前端项目的路径中,找到index.js文件,将端口改为开放式的端口,在前端路径下的跟目录中的 config 文件中.

打开 index. js 文件,找到 location  配置端口的位置,修改为 : 0.0.0.0

相关文章
|
11天前
|
安全 Linux 文件存储
如何在本地服务器部署TeslaMate并远程查看特斯拉汽车数据无需公网ip
如何在本地服务器部署TeslaMate并远程查看特斯拉汽车数据无需公网ip
|
2天前
|
Java Linux Maven
内网服务器部署maven私服简记(上)
内网服务器部署maven私服简记
15 0
|
10天前
|
安全 Unix Linux
Windows如何远程连接服务器?服务器远程连接图文教程
服务器操作系统可以实现对计算机硬件与软件的直接控制和管理协调,任何计算机的运行离不开操作系统,服务器也一样,服务器操作系统主要分为四大流派:Windows Server、Netware、Unix和Linux。今天驰网飞飞将和你分享Windows server远程连接图文教程,希望可以帮助到你
26 4
Windows如何远程连接服务器?服务器远程连接图文教程
|
1天前
|
网络协议 Windows
Windows Server 各版本搭建 DNS 服务器实现域名正反向解析
Windows Server 各版本搭建 DNS 服务器实现域名正反向解析
|
2天前
|
Java Maven
内网服务器部署maven私服简记(下)
内网服务器部署maven私服简记(下)
11 0
|
7天前
|
域名解析 网络协议 安全
服务器部署访问出错的原因和解决办法
部署到服务器后无法访问可能是由于配置错误、权限问题或网络设置不当。解决办法包括检查服务器配置文件、确保文件路径正确、调整权限设置以及检查防火墙和端口设置。
19 4
|
8天前
|
人工智能 安全 机器人
AI电销机器人系统源码部署:freeswitch安装Windows
在Windows上安装FreeSWITCH:访问官网下载安装程序,运行并按提示安装;选择安装路径和组件;等待安装完成;配置FreeSWITCH,修改设置;启动服务;测试其功能;如遇问题,参考官方文档或进行调试故障排除。记得定期更新维护以保证稳定安全。
|
11天前
|
Apache 数据安全/隐私保护 Windows
如何在Windows部署TortoiseSVN客户端并实现公网连接内网VisualSVN服务端
如何在Windows部署TortoiseSVN客户端并实现公网连接内网VisualSVN服务端
|
11天前
|
存储 安全 文件存储
Windows系统本地部署HFS并结合内网穿透实现公网访问本地存储文件
Windows系统本地部署HFS并结合内网穿透实现公网访问本地存储文件
Windows系统本地部署HFS并结合内网穿透实现公网访问本地存储文件

热门文章

最新文章