目录
以下就是Linux部署单机项目和前后端分离项目的优缺点,希望对你有所帮助。
优点:
缺点:
优点:
缺点:
在部署项目到虚拟机之前我们要把我的sql数据和war包在自己的电脑上进行部署,看有没有问题在进行到虚拟机上面进行部署。
主机连接虚拟机共享数据文件和war包项目。
找到sql文件,在数据库里面运行我们的sql文件。
文件选择我的sql文件路径;
解压项目(我们的war包)放入tomcat服务器或者放入任何的其他服务器。我这里以tomcat为例:
在虚拟机中找到tomcat服务器的bin目录下的startup.bat,双击运行后。
回到我们的主机在浏览器中输入ip地址+访问路径即可访问。
如果你的项目运行登录的时候。如果出现用户不存在,可以查看你虚拟机里面的报错,大概是这个项目的配置文件,配置sql的数据库不对。
我们在我们放war包位置,可以看到我们的项目被解压出来了,我们可以在里面找到我们的配置文件,更改我们的数据库名。
我这里的配置文件名是config.properties。
看这些位置是否与虚拟机里的一样。
更改后访问重启tomcat服务,重新访问。
还是一样把我们的war包放入tomcat中的webapp里面。
运行我们的tomcat解析我们的项目之后,找到我们的配置数据库的文件。
在我们的虚拟机里面新建数据库,运行我们所需要的sql文件。
更改我们虚拟机的配置后重启tomcat。
- 启动tomcat
- 在我们的spa项目里面cmd命令打开窗口,输入命令npm run dev。
前后端分离的项目如果直接这么访问就会访问不到,只有虚拟机自己才可访问。
利用nginx做反向代理处理该问题,在nginx文件中找到nginx.conf 文件,将文件种的 location 进行修改。
#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; # } #} }
在nginx根目录下输入cmd进入命令窗口输入 nginx.exe -s reload重启
双击启动文件
最后就可以进行访问了!!!

在spa项目中找到config文件下的index.js将host:'localhost'改为0.0.0.0。
最后也可以进行访问了!!!
