mac m1 安装 Nginx -- 部署VUE项目

1 篇文章 0 订阅

mac m1 安装 Nginx – 部署VUE项目

(一) 安装Nginx

  • (1)由于网络以及其他原因,不使用brew安装,去nginx官网下载

下载地址: http://nginx.org/en/download.html

本次下载版本为1.18.0

  • (2)下载PRCE库,不下载的话,安装过程会报错

下载地址: https://sourceforge.net/projects/pcre/files/

可能的报错内容:

./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.
  • (3)下载SSL

下载地址: https://www.openssl.org/source/

  • (4)将上述下载文件移动到同一自定义目录下,解压缩,也可以用mac自带工具解压
sudo tar zxvf nginx-1.18.0.tar.gz
...
  • (5)编译安装–Configure Nginx
cd nginx-1.18.0/

sudo ./configure --with-pcre=../pcre-8.45/ 

sudo make

sudo make install
  • (6)nginx加入环境变量
vim ~/.zshrc

export PATH="/usr/local/nginx/sbin:$PATH"

source ~/.zshrc
  • (7)验证–在目标文件夹下生成nginx目录
cd /usr/local

sudo ./nginx

访问 localhost,安装成功

(二) 部署VUE项目

  • (1) 打包vue项目,生成dist目录
npm run build
  • (2) 配置Nginx服务器

打开nginx目录

cd /usr/local/nginx/conf

打开 nginx.conf 文件,添加服务器

root: 将接收到的资源根据/usr/local/nginx/html/dist文件夹去查找资源
index: 默认去上述路径中找到index.html或者index.htm

    server {
       listen       5050;
       server_name  localhost;
       location / {
          root   /usr/local/nginx/html/dist;
          index  index.html index.htm;

        #    proxy_pass http://localhost:18080;
       }
    }
  • (3)部署项目

将dist目录上传到上面的指定路径,并启动nginx服务

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

浏览器访问服务器地址 http://localhost:5050

  • (4) nginx上线配置

nginx部署后不存在跨域问题

#nginx.conf
...
http {
    server {
        listen       8082;                   //监听的端口
        server_name  localhost;              

        location / {                         // 表示 以'/'开头的请求怎样处理
            root   html;                     //指定root文件夹为 上面提到的html文件夹
            index  index.html;               //返回index.html
        }
        location /bpi{                       // 表示 以'/bpi'开头的请求 怎样处理
            proxy_pass http://localhost:8081;     //以同样的蚕食向这个地址请求,并返回给客户端
        }

        error_page  404              /index.html;   //404的时候就返回index.html
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

anjushi_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值