【问题标题】:Ubuntu 18, conflict between PM2 and NGinx (err address in use)Ubuntu 18,PM2 和 NGinx 冲突(使用中的错误地址)
【发布时间】:2020-06-20 14:52:28
【问题描述】:

我启动了 PM2,然后当我运行 nginx start 命令时。 PM 2 开始时没有问题,但是当我启动 NGINX 时。我总是遇到这个错误。

nginx[26370]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) 这是我的配置文件

server {

    listen 80 default_server;
    listen [::]:80 ipv6only=on;


    # SSL configuration
    #
     listen 443 ssl;
    # listen [::]:443 ssl default_server;


    #
    # Note: You should disable gzip for SSL traffic.
    # See: https://bugs.debian.org/773332
    #
    # Read up on ssl_ciphers to ensure a secure configuration.
    # See: https://bugs.debian.org/765782
    #
    # Self signed certs generated by the ssl-cert package
    # Don't use them in a production server!
    #
    # include snippets/snakeoil.conf;

    #root /var/www/html;
    root /root/my-website;
    #app.js;
    index index.html index.htm index.nginx-debian.html app.js;

    server_name mywebsite.com;
    ssl_certificate /root/folder/mywebsite.com.chained.crt;
    ssl_certificate_key /root/folder/mywebsite.com.key;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';

    location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            proxy_pass    http://localhost:80;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
    }

    # pass PHP scripts to FastCGI server
    #
    #location ~ \.php$ {
    #       include snippets/fastcgi-php.conf;
    #
    #       # With php-fpm (or other unix sockets):
    #       fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
    #       # With php-cgi (or other tcp sockets):
    #       fastcgi_pass 127.0.0.1:9000;
    #}

【问题讨论】:

    标签: node.js express ubuntu nginx


    【解决方案1】:

    Nginx 的默认工作端口是 80,就像任何其他 Web 服务器一样。 node app使用的端口不应该是80,可以选择3000到50000之间合适的端口值,我的建议是8080。

    之后,使用 pm2 启动您的节点应用程序,然后更改 nginx 配置中的 proxy_pass 部分。

    proxy_pass http://localhost:<new_app_port>;
    

    另外,我不建议以这种方式使用 proxy_pass。通过定义 upstrean 来使用它会更好。您可以在一个地址下扩展负载平衡和多机应用程序。

    Nginx 上游配置参考:http://nginx.org/en/docs/http/load_balancing.html

    【讨论】:

      猜你喜欢
      • 2015-06-13
      • 1970-01-01
      • 2016-09-21
      • 1970-01-01
      • 2021-04-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-31
      相关资源
      最近更新 更多