arm的ubuntu启动node

在arm上的ubuntu使用npm run dev的时候,在package.json中的scripts的dev中配置0.0.0.0的时候,启动会报错

根本原因:ARM Ubuntu 上的 Node.js os.networkInterfaces() 系统调用有权限问题。

只能使用localhost,推荐使用nginx转发或者docker,下面以nginx配置为例:

1. 安装 nginx

sudo apt install nginx

2. 创建 nginx 配置

sudo vim /etc/nginx/sites-available/vite-proxy.conf

bash 复制代码
server {
    # 外面访问5174转发到机器上的5173上
    listen 5174;
    listen [::]:5174;
    server_name _;
    
    location / {
    		# 5173是node启动的端口
        proxy_pass http://localhost:5173;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

3. 修改 package.json

bash 复制代码
"scripts": {
  "dev": "vite --host localhost"
}

4. 启用配置

bash 复制代码
sudo ln -s /etc/nginx/sites-available/vite-proxy /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx

5. 现在其他机器可以通过 http://你的ARM设备IP:3000 访问

6.如果做了外网域名访问,还需要修改vite.config.ts或者vite.config.js文件

bash 复制代码
在server中增加域名配置
server: {
      port: 5173,
      host: true,
      // 允许的域名列表
      allowedHosts: [
        // 你的域名
        'abcd.com',
        'www.abcd.com',

        // 本地访问
        'localhost',
        '127.0.0.1',
        // 通配符匹配域名
        '.abcd.com'
      ],
}

7.启动node和nginx

复制代码
npm run dev
service nginx start
相关推荐
orion571 天前
Missing Semester Class1:course overview and introduction of shell
linux
用户120487221611 天前
Linux驱动编译与加载
linux·嵌入式
用户805533698031 天前
Input 子系统架构:Core、Handler、Driver 三层是怎么协作的
linux·嵌入式
用户805533698031 天前
RK-Forge外设系列开篇 - 把板子从「能启动」变成「能用」:Ethernet/SPI/MMC 三个纯接线外设
linux·github·嵌入式
七歌杜金房2 天前
我终于又有了自己的 Linux 电脑
linux·debian·mac
tntxia3 天前
linux curl命令详解_curl详解
linux
扛枪的书生3 天前
Linux 网络管理器用法速查
linux
顺风尿一寸3 天前
Java Socket 内核之旅:从 SocketChannel.read() 到 tcp_recvmsg 与 epoll 的完整调用链路
linux
XIAOHEZIcode3 天前
Ubuntu 终端美化全栈指南:Bash 到 Kitty 踩坑实录
linux·ubuntu·命令行
唐青枫4 天前
别再只会用 cron:Linux systemd Timer 定时任务实战详解
linux