服务器部署vue

1.下载及安装

打开服务器终端,在终端中输入以下命令,下载nginx安装包。

wget http://nginx.org/download/nginx-1.20.2.tar.gz

其中nginx版本可以自己选择,具体版本可查看此链接:nginx news
将下载的压缩包解压,输入指令:

tar -zvxf nginx-1.20.2.tar.gz
cd nginx-1.20.2

安装nginx

./configure --with-http_ssl_module --with-http_gzip_static_module

2. 安装nginx的时我遇到以下问题(如果nginx安装成功可忽略)

1,PCRE 缺失,报错代码

./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre= option.

解决办法:安装 PCRE

yum -y install pcre-devel

安装完再次执行 

./configure --with-http_ssl_module --with-http_gzip_static_module

又报了个错,如下,出现此报错信息,意思就是nginx有相关前置依赖openssl-devel没有安装

./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option.

 解决办法:安装下openssl-devel

yum -y install openssl openssl-devel

 安装完再次执行

./configure --with-http_ssl_module --with-http_gzip_static_module

 没出现报错,那么继续

 

 三.继续安装nginx

make

 如下:

make install

 四.启动程序

进入目录,启动nginx

cd /usr/local/nginx/sbin/
./nginx

 如下:

查看版本:

./nginx -v

五、配置nginx
在将dist文件传输至服务器以后,需要对nginx进行配置。
在服务器中找到/usr/local/nginx/conf/nginx.conf文件,打开nginx.conf文件修改以下内容:

1)打开winscp

 将打包好的vue文件dist放入指定目录

2).修改服务器端口
listen默认端口为8080,因为个人需求所以改为了8081,server_name填写localhost即可。 

3)修改dist存放路径

修改成刚才dist文件存放的路径,添加一行try_files $uri $uri/ @router;,防止刷新页面出现404。 

 五、进入界面和项目更新

1.进入界面

配置完成后需要重新启动以下nginx,可以用如下指令:

nginx -s stop
cd /usr/local/nginx/sbin/
./nginx

 运行,在浏览器中输入服务器IP:端口

2.项目更新

如果后续前端项目文件需要更新,则再次生成dist文件,将新的dist文件替换至服务器文件夹相同位置中,无需重启nginx。
若发现更新后前端界面无变化,可重启nginx后再次进入界面查看。

如输入地址还是打不开网页

可能遇到以下问题:

1.端口被占用

解决办法:换个端口号并保存,打开Winscp软件找到指定目录 /usr/local/nginx/conf/nginx.conf

 再执行

./nginx -s stop
cd /usr/local/nginx/sbin/
./nginx

Tips:关于命令

进入目录,启动nginx

cd /usr/local/nginx/sbin/
./nginx

查看nginx运行状态:

ps aux | grep nginx
  • 停止运行:

./nginx -s stop
  • 查看版本:

./nginx -v
  • 检查配置文件:

./nginx -t

查看8080端口被占用的进程

lsof -i:8080

查看进程号PID 

ps -ef|grep nginx 

 强制停止:

kill -9 进程号

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
服务器部署Vue和Django项目涉及以下步骤: 1. 首先,你需要在服务器上安装Docker,并下载并安装Nginx作为反向代理服务器Nginx将用于处理用户请求并将其转发到正确的服务器上。 2. 然后,你需要将Vue客户端和Django服务器分别部署在不同的服务器上。Vue客户端将托管静态页面,而Django服务器将提供服务。这样做可以分担高并发压力。 3. 在Vue客户端服务器上,你需要下载并安装Nginx镜像,并配置Nginx以使其能够正确地转发请求到Django服务器。这将解决客户端发送的请求应该访问哪个服务器的问题。 4. 在Django服务器上,你需要安装MySQL和Redis镜像,并配置它们以满足你的项目需求。此外,你还需要配置uwsgi服务器来执行Django项目。 5. 最后,你需要确保静态文件可以被访问。你可以通过从服务端项目中收集静态文件,并在Nginx配置中添加静态文件的访问支持来实现这一点。 总结起来,服务器部署Vue和Django项目需要安装Docker、Nginx、MySQL、Redis和uwsgi等组件,并配置它们以满足项目的需求。此外,还需要合理地分配服务器架构,使用Nginx作为反向代理服务器来转发请求,并保证静态文件的访问支持。这样可以提高系统的性能和稳定性。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [vue+django项目部署](https://blog.csdn.net/weixin_42065178/article/details/124418986)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [博客系统源码,基于Django v2.0.7 + Python3.6 + VUE2.0](https://download.csdn.net/download/weixin_47367099/85342192)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值