找回密码
 立即注册

请详细介绍一下在宝塔的nginx上直接部署 ant design pro 的dist版本需要的环境、步骤 ...

已有 549 次阅读2023-5-27 18:16 |个人分类:系统开发

在宝塔的Nginx上部署Ant Design Pro的dist版本需要以下环境和步骤:

- 确保您已安装了Node.js和NPM。

- 安装npx工具:

```
npm install -g npx
```

- 在Ant Design Pro项目的根目录下,使用以下命令进行打包:

```
npm run build
```

- 打包完成后,将dist目录复制到您要部署的服务器上。

- 在宝塔面板中创建一个站点,例如`pro.mydomain.com`。

- 在站点设置中,选择“反向代理”,将`/`转发到`http://localhost:8000`。其中,`8000`是Ant Design Pro的默认端口。

![宝塔面板配置反向代理](https://cdn.nlark.com/yuque/0/2021/png/274499/1632758210909-5ab0271a-3a90-4532-8fb5-2b03e9e6128e.png)

- 使用宝塔面板的文件管理器,在站点目录下创建一个空白的index.html文件。

- 在站点目录下创建一个新的名为`static`的文件夹。

- 将dist目录中的所有内容复制到`static`文件夹中。

- 创建一个新的名为`pro.conf`的Nginx配置文件,文件路径为`/www/server/panel/vhost/nginx/pro.mydomain.com.conf`。文件内容如下:

```
server {
listen 80;
server_name pro.mydomain.com;

root /www/wwwroot/pro.mydomain.com;
index index.html index.htm;

location / {
try_files $uri $uri/ /index.html;
}

location /api/ {
proxy_pass http://localhost:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

location /socket.io/ {
proxy_pass http://localhost:8000;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 86400;
}
}
```

其中,

- `server_name`是您的站点域名。
- `root`是站点根目录,需要设置为您的站点目录。
- `location /`部分是用来匹配前端项目中的路由。
- `location /api/`和`location /socket.io/`部分是将/api和/socket.io请求转发到Ant Design Pro的服务端口。

- 在宝塔面板中,重载Nginx配置文件。

![宝塔面板重载Nginx配置文件](https://cdn.nlark.com/yuque/0/2021/png/274499/1632758387372-eb1c939e-0d06-4c0d-86ad-1adce85b60c3.png)

- 浏览器访问`http://pro.mydomain.com`,您应该能够看到Ant Design Pro的登录页面。

至此,您已经成功地在宝塔的Nginx上部署了Ant Design Pro的dist版本。

路过

雷人

握手

鲜花

鸡蛋

评论 (0 个评论)

facelist

您需要登录后才可以评论 登录 | 立即注册

QQ|Archiver|手机版|小黑屋|通达产控投资 ( 粤ICP备2023021749号-1|粤公网安备 44030402006137号 )

GMT+8, 2025-4-25 20:50 , Processed in 0.043168 second(s), 7 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

返回顶部