gpt4 book ai didi

http - 运行 uwsgi emperor 模式给出 nginx 错误

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:28:41 25 4
gpt4 key购买 nike

如果我正常运行 uwsgi(非 emperor 模式),nginx 可以完美运行。

如果我在 emperor 模式下配置 uwsgi,我会遇到各种我无法解决的错误。

这是我的 nginx.conf 文件:

worker_processes  1;
worker_rlimit_nofile 8192;

events {
worker_connections 8192;
#multi_accept on; # does not matter if I use multi-accept
use epoll; # or epoll, same errors
}

http {
large_client_header_buffers 2 1k;
client_body_buffer_size 10k;
client_header_buffer_size 1k;
client_max_body_size 8m;
request_pool_size 32k;
connection_pool_size 256;
ignore_invalid_headers on;

sendfile on;
tcp_nopush on;
server_names_hash_bucket_size 128;
keepalive_timeout 90;
gzip on;
gzip_http_version 1.0;
gzip_proxied any;
gzip_min_length 500;
gzip_disable "MSIE [1-6]\.";
gzip_types text/plain text/xml text/css
text/comma-separated-values
text/javascript
application/x-javascript
application/atom+xml;

# Configuration for Nginx
server {
# Running port
listen 80;
listen 127.0.0.1:27070;
server_name 127.0.0.1 myserver_name.com;
charset utf-8;
access_log /log/nginx_access.log;
error_log /log/nginx_error.log;

# Proxying connections to application servers
location /myapplication/ {
include uwsgi_params;
uwsgi_buffering off;
uwsgi_param SCRIPT_NAME /myapplication;
uwsgi_modifier1 30;
uwsgi_pass 127.0.0.1:27070;
proxy_pass http://127.0.0.1:27070;
proxy_redirect off;
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-host $server_name;
} # end mysite
} # end server
} # end http

vassals-default.ini 文件:

[uwsgi]
log-date = true
emperor=/etc/uwsgi
emperor-use-clone = fs,net,ipc,pid,uts
emperor-tyrant = true
vassals-include = /opt/uwsgi/vassals-default.ini
master = true
cap = setgid, setuid
vassal-set = processes=8
vassal-set = enable-metrics=1
vassal_name = %n
socket = /tmp/sockets/%n.sock
chmod-socket = 770
logto = /opt/uwsgi/%n.log

我的应用程序.ini 文件:

[uwsgi]
domain = myserver_name.com
app-name = myapplication
uid = myapplication
gid = myapplication
socket=/tmp/sockets/myapplication.sock
chdir = /opt/myapplication/myapp
virtualenv = /opt/myapplication/webapp-20150203/
module = WSGI:app
callable = app
processes = 2
buffer-size=32768
http-buffer-size=32768
daemonize = /opt/uwsgi/myapplication.log
pidfile = /opt/uwsgi/myapplication.pid
logto = /opt/uwsgi/uwsgi.log
debug = true
disable-logging = false
thunder-lock = true
enable-threads = true
harakiri = 30

套接字文件:

[root@npi uwsgi]# ls -l /tmp/sockets
srwsrws--- 1 sadlesum sadlesum 0 Jul 16 13:48 myapplication.sock
srwxrwx--- 1 root root 0 Jul 16 13:48 vassals-default.sock

日志文件看起来不错:

我的应用程序日志:

Thu Jul 16 13:48:25 2015 - *** starting uWSGI sub-Emperor ***
Thu Jul 16 13:48:25 2015 - announcing my loyalty to the Emperor...
Thu Jul 16 13:48:25 2015 - uwsgi socket 0 bound to UNIX address /tmp/sockets/myapplication.sock fd 3
Thu Jul 16 13:48:25 2015 - uwsgi socket 1 bound to UNIX address /tmp/sockets/vassals-default.sock fd 4
Thu Jul 16 13:48:25 2015 - Python version: 2.7.6 (default, Jan 11 2014, 21:49:01) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)]
Thu Jul 16 13:48:25 2015 - Set PythonHome to /opt/myapplication/webapp-20150203/
Thu Jul 16 13:48:25 2015 - Python main interpreter initialized at 0x10f7470
Thu Jul 16 13:48:25 2015 - python threads support enabled
Thu Jul 16 13:48:25 2015 - your server socket listen backlog is limited to 100 connections
Thu Jul 16 13:48:25 2015 - your mercy for graceful operations on workers is 60 seconds
Thu Jul 16 13:48:25 2015 - mapped 304320 bytes (297 KB) for 2 cores
Thu Jul 16 13:48:25 2015 - *** Operational MODE: preforking ***
Thu Jul 16 13:48:29 2015 - WSGI app 0 (mountpoint='') ready in 4 seconds on interpreter 0x10f7470 pid: 26688 (default app)
Thu Jul 16 13:48:29 2015 - *** uWSGI is running in multiple interpreter mode ***
Thu Jul 16 13:48:29 2015 - spawned uWSGI master process (pid: 26688)
Thu Jul 16 13:48:29 2015 - spawned uWSGI worker 1 (pid: 26703, cores: 1)
Thu Jul 16 13:48:29 2015 - spawned uWSGI worker 2 (pid: 26704, cores: 1)

以皇帝模式启动uwsgi:

uwsgi --emperor/opt/uwsgi --vassals-include/opt/uwsgi/vassals-default.ini --master --die-on-term

*** starting uWSGI Emperor ***
Python version: 2.7.6 (default, Jan 11 2014, 21:49:01) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)]
*** has_emperor mode detected (fd: 6) ***
[uWSGI] getting INI configuration from saddlesum.ini
[uWSGI] getting INI configuration from /opt/uwsgi/vassals-default.ini
*** has_emperor mode detected (fd: 7) ***
[uWSGI] getting INI configuration from vassals-default.ini
[uWSGI] getting INI configuration from /opt/uwsgi/vassals-default.ini
Thu Jul 16 13:48:25 2015 - [emperor] vassal myapplication.ini is now loyal
Thu Jul 16 13:48:25 2015 - [emperor] vassal vassals-default.ini is now loyal
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0xb16870
your mercy for graceful operations on workers is 60 seconds
*** Operational MODE: no-workers ***
spawned uWSGI master process (pid: 26686)
Thu Jul 16 13:48:25 2015 - [emperor] vassal vassals-default.ini has been spawned
Thu Jul 16 13:48:25 2015 - [emperor] vassal vassals-default.ini is ready to accept requests
Thu Jul 16 13:48:29 2015 - [emperor] vassal myapplication.ini has been spawned
Thu Jul 16 13:48:29 2015 - [emperor] vassal myapplication.ini is ready to accept requests

当我尝试在 firefox(或 Chrome)中访问我的 webapp 时,出现以下错误:

如果我的 nginx.conf 文件中有这一行:

proxy_pass          http://127.0.0.1:27070;

当 nginx.conf 文件中存在上述 proxy_pass 行时错误 400 错误请求:

Error 400 bad request

在 nginx.conf 文件中注释掉上面的 proxy_pass 行时出现错误 502 bad gateway:

502 bad gateway result

此外,当出现 502 bad gateway 错误时,我还在我的 nginx_error.log 文件中看到了这一点:

2015/07/16 14:10:18 [error] 28289#0: *1 upstream prematurely closed connection while reading response header from upstream, client: 127.0.0.1, server: 127.0.0.1, request: "GET /myapplication/ HTTP/1.1", upstream: "uwsgi://127.0.0.1:27070", host: "myserver_name.com", referrer: "http://myserver_name.com/"

最佳答案

尝试像这样在 setting.py 中将本地主机或您的 ip/域添加到 ALLOWED_HOSTS

ALLOWED_HOSTS = ['localhost', '127.0.0.1', 'your.server.ip.here']

同时删除这些:

监听 127.0.0.1:27070;

uwsgi_pass 127.0.0.1:27070;

proxy_pass http://127.0.0.1:27070 ;

并让 nginx 使用 unix socket 而不是在你的 ini 文件中

socket=/tmp/sockets/myapplication.sock

关于http - 运行 uwsgi emperor 模式给出 nginx 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31461770/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com