linux 使用nginx部署web(vue、react)项目
当然,如果你觉得文章有什么让你觉得不合理、或者有更简单的实现方法又或者有理解不来的地方,希望你在看到之后能够在评论里指出来,我会在看到之后尽快的回复你。配置文件在 /usr/local/nginx/conf 目录下,将配置文件拉到本地编辑,改完了别忘了上传覆盖。指定安装路径(如果不指定,将默认安装在/usr/local/bin)location - root字段: 前端项目存放路径,目录随意。如果
前言
基于:操作系统 CentOS 7.6
工具:Xshell7、Xftp7
服务器基础环境:
- node
所需服务器基础环境,请自行百度了解、安装。
1.安装依赖
安装gcc、gcc-c++
yum install gcc gcc-c++ -y
安装pcre、pcre-devel
yum install pcre pcre-devel -y
安装zlib、zlib-devel
yum install zlib zlib-devel -y
安装openssl、openssl-devel
yum install openssl openssl-devel -y
2.下载及解压
在 /usr/local 路径下,创建 nginx文件夹并进入
cd /usr/local
mkdir nginx && cd ./nginx
下载压缩包
wget http://nginx.org/download/nginx-1.19.10.tar.gz
nginx 版本可以自定义,后续步骤对应修改即可
解压
tar -zxvf nginx-1.19.10.tar.gz
3.配置编译及安装
cd nginx-1.19.10
./configure --prefix=/usr/local/nginx
–prefix:指定 nginx 的安装路径,默认安装在 /usr/local/bin
编译、安装
make && make install
如果提示 -bash: make: command not found,执行 yum install make -y 即可
4.配置 nginx.conf 文件
配置文件在 /usr/local/nginx/conf 目录下,拉到本地编辑,改完之后上传覆盖
server {
listen 80;
server_name localhost;
location / {
root /var/www/project;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
}
说明
listen:服务器端口,如果不是80端口,需配置安全组
server_name:域名,没有通过公网IP访问即可
location - root:前端项目存放路径
5.上传前端项目
根据 nginx.conf 配置,将项目上传到指定目录
6.启动 nginx
cd /usr/local/nginx/sbin
./nginx
其他常用命令
关闭
./nginx -s stop
重启
./nginx -s reload
7.效果图
如果本篇文章对你有帮助的话,很高兴能够帮助上你。
当然,如果你觉得文章有什么让你觉得不合理、或者有更简单的实现方法又或者有理解不来的地方,希望你在看到之后能够在评论里指出来,我会在看到之后尽快的回复你。
更多推荐
所有评论(0)