NGINX 加载网站失败
NGINX fails to load site
我有一个 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/ =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 尝试加载站点,但是错误是 "forbidden":
*23053 directory index of "/opt/bench/erpnext/sites/" is forbidden
如何在 NGINX 中解决这个问题?
我已经解决了
解决方法是设置nginx监听其他端口,比如8020,然后重启服务器。
重启后我检查 python 开始监听 8000 端口和 8020 端口的 nginx。
这样就成功了。我真的不知道为什么 python 正在侦听端口 8000 以及如何更改它,但现在没关系了。
问候
海梅
我有一个 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/ =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 尝试加载站点,但是错误是 "forbidden":
*23053 directory index of "/opt/bench/erpnext/sites/" is forbidden
如何在 NGINX 中解决这个问题?
我已经解决了
解决方法是设置nginx监听其他端口,比如8020,然后重启服务器。
重启后我检查 python 开始监听 8000 端口和 8020 端口的 nginx。
这样就成功了。我真的不知道为什么 python 正在侦听端口 8000 以及如何更改它,但现在没关系了。
问候 海梅