首页 » 脚本文章 » 原来前端部署这么简单(部署这么简单服务器虚拟机网段)「前端怎么部署到服务器」

原来前端部署这么简单(部署这么简单服务器虚拟机网段)「前端怎么部署到服务器」

落叶飘零 2024-07-24 02:05:17 脚本文章 0

扫一扫用手机浏览

文章目录 [+]

下载完之后就可以去VMWare 新建虚拟机,然后就是傻瓜式下一步,遇到下面的界面,选择对应的iso镜像文件的路径即可,遇到设置用户名和密码的界面,要记得用户名和密码,后面要用到,之后就是一直下一步到完成。

安装完之后在左边的tab会出现对应安装好的虚拟机,这个时候启动即可

若是启动的过程中出现弹框报错 VMware提示此主机支持Intel VT-x但Intel VT-x处于禁用状态,大概率是BIOS设置的某一项为disable,所以大家需要自己的电脑进入bios设置,开启对应的选项并保存重启。

原来前端部署这么简单(部署这么简单服务器虚拟机网段) 原来前端部署这么简单(部署这么简单服务器虚拟机网段) 脚本文章
(图片来自网络侵删)

远程连接

这个步骤有服务器的可以直接跳过,有了服务器之后我们就可以先与服务器建立连接,这样后续操作部署之类的也会比较方便。

首先打开虚拟机的虚拟网络编辑器,位置如下

原来前端部署这么简单(部署这么简单服务器虚拟机网段) 原来前端部署这么简单(部署这么简单服务器虚拟机网段) 脚本文章
(图片来自网络侵删)

打开主机的命令行,查询ip配置,进行网络配置,要特别注意子网IP中网段要与本地电脑的网段必须保持一致

网关IP中网段必须要与本地电脑的默认网关的网段保持一致

上述配置完之后,就是右键虚拟机->设置->选择第2步中设置了Nat模式的网卡

然后就可以打开虚拟机的命令行,然后查看一下ip(输入命令 ifcofig)

然后就可以根据ip进行连接,我是通过xftp进行连接,用户名得用root这是默认超级管理员的用户名(因为后续部署前端项目需要该权限),密码则是最开始配置虚拟机设置的密码,然后就远程成功了

前端资源

可以远程之后我们就可以直接将打包好的前端资源部署到服务器,以我为例,通过xftp将dist上传到服务器的路径/var/www/test

这个时候我们在我们的主机,浏览器访问远程ip,发现什么也没有

这是为什么?

因为我们没有进行nginx的映射,所以需要安装nginx

Nginx配置

sudo yum install epel-releasesudo yum install nginx

启动nginx

sudo systemctl start nginx

启动完之后我们需要更改配置文件,配置文件路径在 etc/nginx/nginx.conf

# For more information on configuration, see:# Official English Documentation: http://nginx.org/en/docs/# Official Russian Documentation: http://nginx.org/ru/docs/user nginx;worker_processes auto;error_log /var/log/nginx/error.log;pid /run/nginx.pid;# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.include /usr/share/nginx/modules/.conf;events { worker_connections 1024;}http { 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 /var/log/nginx/access.log main; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 4096; include /etc/nginx/mime.types; default_type application/octet-stream; # Load modular configuration files from the /etc/nginx/conf.d directory. # See http://nginx.org/en/docs/ngx_core_module.html#include # for more information. include /etc/nginx/conf.d/.conf; server { listen 80; listen [::]:80; server_name localhost; location / { root /var/www/test/; index index.html index.htm; } # Load configuration files for the default server block. include /etc/nginx/default.d/.conf; error_page 404 /404.html; location = /404.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } }}

修改完之后重启nginx

sudo systemctl restart nginx

主机通过浏览器访问虚拟机ip,发现成功了

标签:

相关文章

上古卷轴吸血鬼病暗影中的诅咒之谜

《上古卷轴》作为一款经典的奇幻游戏,自问世以来,便以其独特的世界观和丰富的故事情节吸引了无数玩家。在游戏中,吸血鬼病作为一项神秘而...

脚本文章 2025-02-18 阅读0 评论0