【问题标题】:NGINX fails to load siteNGINX 无法加载站点
【发布时间】:2019-04-05 03:29:45
【问题描述】:

我有一个 nginx 站点在端口 8000 上监听。我有 Apache 在端口 80 上监听。

当我尝试加载 nginx 站点时,日志中显示此错误:

2019/03/27 20:13:06 [alert] 7845#7845: 1024 worker_connections are not enough
2019/03/27 20:13:06 [error] 7845#7845: *17498 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 127.0.0.1, server: erp.example.com, request: "GET / HTTP/1.0", upstream: "http://127.0.0.1:8000/", host: "erp.example.com"

并在浏览器中显示默认的 502 页面,位于“/opt/bench/bench-repo/bench/config/templates”文件夹中。

这里可能有什么问题?

这是完整的 nginx.conf 文件:

upstream erpnext-frappe {
    server 127.0.0.1:8000 fail_timeout=0;
}

upstream erpnext-socketio-server {
    server 127.0.0.1:9000 fail_timeout=0;
}



# setup maps


# server blocks





server {
    listen 8000;
    server_name
        erp.example.com
        ;

    root /opt/bench/erpnext/sites;





    add_header X-Frame-Options "SAMEORIGIN";

    location /assets {
        try_files $uri =404;
    }

    location ~ ^/protected/(.*) {
        internal;
        try_files /erp.example.com/$1 =404;
    }

    location /socket.io {
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header X-Frappe-Site-Name erp.example.com;
        proxy_set_header Origin $scheme://$http_host;
        proxy_set_header Host $host;

        proxy_pass http://erpnext-socketio-server;
    }

    location / {
        try_files /erp.example.com/public/$uri @webserver;
    }

    location @webserver {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Frappe-Site-Name erp.example.com;
        proxy_set_header Host $host;
        proxy_set_header X-Use-X-Accel-Redirect True;
        proxy_read_timeout 120;
        proxy_redirect off;

        proxy_pass  http://erpnext-frappe;
    }

    # error pages
    error_page 502 /502.html;
    location /502.html {
        root /opt/bench/bench-repo/bench/config/templates;
        internal;
    }

    # optimizations
    sendfile on;
    keepalive_timeout 15;
    client_max_body_size 50m;
    client_body_buffer_size 16K;
    client_header_buffer_size 1k;

    # enable gzip compresion
    # based on https://mattstauffer.co/blog/enabling-gzip-on-nginx-servers-including-laravel-forge
    gzip on;
    gzip_http_version 1.1;
    gzip_comp_level 5;
    gzip_min_length 256;
    gzip_proxied any;
    gzip_vary on;
    gzip_types
        application/atom+xml
        application/javascript
        application/json
        application/rss+xml
        application/vnd.ms-fontobject
        application/x-font-ttf
        application/font-woff
        application/x-web-app-manifest+json
        application/xhtml+xml
        application/xml
        font/opentype
        image/svg+xml
        image/x-icon
        text/css
        text/plain
        text/x-component
        ;
        # text/html is always compressed by HttpGzipModule
}

我与一个也安装了这个应用程序并可以运行的虚拟机进行了比较,它几乎是一样的。不同的是,在另一台机器上,nginx 监听 80 端口,python 监听 8000 端口。

感谢任何帮助。

编辑:

我已将位置/配置更改为:

location / {
                try_files $uri $uri/ =404;
        }

也就是我去掉了proxy pass配置,现在nginx尝试加载站点,但是报错是“forbidden”:

*23053 directory index of "/opt/bench/erpnext/sites/" is forbidden

如何在 NGINX 中解决这个问题?

【问题讨论】:

  • 为什么用同一个8000端口监听python和nginx?
  • 不..你不明白。 NGINX 工作的另一台 PC,NGINX 在端口 80 上监听,python 在端口 8000 上监听。我的 PC,NGINX 不工作,Apache 在端口 80 上监听,NGINX 在端口 8000 上监听。此外,配置文件是由自动创建的台安装脚本。我只是将端口 80 更改为端口 8000
  • 我已经编辑了问题。
  • @jstuardo 问题是你有太多的变量——没有人有 15 分钟的时间来阅读这个问题来理解相同端口上所有不相关的服务器。几乎一样吗?听起来它几乎可以工作,所以,有什么问题?!
  • @cnst 我不明白你的意思。你问我问题是什么?显示错误时是否不清楚?

标签: nginx nginx-location nginx-config


【解决方案1】:

我已经解决了。

解决方法是设置 nginx 监听另一个端口,例如 8020。然后我重新启动了服务器。

重新启动后,我检查了 python 开始监听端口 8000 和端口 8020 上的 nginx。

这样就成功了。我真的不知道为什么 python 监听 8000 端口以及如何更改它,但现在已经不重要了。

问候 詹姆

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-04-24
    • 2017-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多