NGINX无法加载站点

时间:2019-03-27 23:23:57

标签: nginx nginx-location nginx-config

我有一个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;
        }

也就是说,我删除了代理通过配置,现在nginx尝试加载该站点,但是错误是“禁止的”:

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

如何在NGINX中解决此问题?

1 个答案:

答案 0 :(得分:1)

我已经解决了。

解决方案是将nginx设置为侦听另一个端口(例如8020)。然后重新启动服务器。

重启后,我检查了python是否开始侦听端口8000和nginx侦听端口8020。

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

问候 海梅