You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu 18.04 VPS安装Nginx遇libc6/libcrypt1依赖错误求解决

解决Ubuntu 18.04上Nginx安装依赖错误及SSL配置问题

一、修复Nginx安装的依赖问题

Ubuntu 18.04默认源中的Nginx版本依赖更高版本的libc6和libcrypt1,系统自带库版本不满足需求,需改用Nginx官方适配18.04的稳定版源:

  1. 清理损坏包及残留Nginx文件

    sudo apt-get autoremove && sudo apt-get clean && sudo apt-get update
    sudo apt-get remove --purge nginx nginx-core nginx-full nginx-light
    
  2. 添加Nginx官方Bionic(Ubuntu 18.04)源

    echo "deb http://nginx.org/packages/stable/ubuntu/ bionic nginx" | sudo tee /etc/apt/sources.list.d/nginx.list
    echo "deb-src http://nginx.org/packages/stable/ubuntu/ bionic nginx" | sudo tee -a /etc/apt/sources.list.d/nginx.list
    
  3. 导入Nginx签名密钥并完成安装

    curl -fsSL https://nginx.org/keys/nginx_signing.key | sudo apt-key add -
    sudo apt-get update && sudo apt-get install nginx
    

二、解决Nginx配置的Brotli错误

官方源安装的Nginx默认未编译Brotli模块,若之前的nginx.conf中存在相关指令,直接注释即可:

  • 编辑主配置文件:sudo nano /etc/nginx/nginx.conf
  • 找到所有以brotli开头的行(如brotli on;、brotli_types text/plain ...;),在行首添加#注释
  • 检测配置有效性:sudo nginx -t

三、配置Nginx反向代理+SSL,解决前端API调用安全错误

假设你的Node.js服务运行在8000端口,通过Nginx配置HTTPS反向代理实现SSL访问:

  1. 安装Certbot获取免费SSL证书

    sudo apt-get install certbot python-certbot-nginx
    
  2. 自动获取证书并配置Nginx
    替换your-domain.com为你的实际域名:

    sudo certbot --nginx -d your-domain.com
    
  3. 手动调整反向代理配置(若Certbot未自动完成)
    编辑Nginx站点配置文件(如/etc/nginx/conf.d/default.conf):

    server {
        listen 443 ssl;
        server_name your-domain.com;
    
        ssl_certificate /etc/letsencrypt/live/your-domain.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/your-domain.com/privkey.pem;
    
        location / {
            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;
            proxy_set_header X-Forwarded-Proto $scheme;
        }
    }
    
    # HTTP请求强制跳转至HTTPS
    server {
        listen 80;
        server_name your-domain.com;
        return 301 https://$host$request_uri;
    }
    
  4. 重启Nginx使配置生效

    sudo systemctl restart nginx
    
  5. 验证Node.js服务状态
    确保PM2管理的Node服务正常运行:

    pm2 status
    

内容的提问来源于stack exchange,提问作者Aniket

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.04 09:31:31