简而言之,Waitress 是一个专注于运行 Python Web 应用程序的服务器,而 Nginx 是一个通用的高性能 Web 服务器,适用于托管各种类型的 Web 内容和服务。在一些场景中,你可能会将 Waitress 与 Nginx 结合使用,其中 Nginx 充当反向代理服务器,而 Waitress 处理 Python Web 应用程序的请求。这样的组合可以充分利用 Nginx 的高性能和 Waitress 的专业性。
2.为什么使用Waitress而不是其他的服务器,例如uWSGI,gunicorn
这与我的开发环境与生产环境有关,我使用的环境皆是windows,而当我试图在windows上安装uWSGI,gunicorn时出现了错误,修改到最后还是放弃了这个方案
C:UsersAdministrator>pip install uwsgi -i https://pypi.tuna.tsinghua.edu.cn/si
mple
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting uwsgi
Using cached https://pypi.tuna.tsinghua.edu.cn/packages/79/73/b5def500729e134d
1cb8dfc334e27fa2e9cfd4e639c1f60c6532d40edaed/uwsgi-2.0.23.tar.gz (810 kB)
Installing build dependencies ... done
Getting requirements to build wheel ... error
error: subprocess-exited-with-error
× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> [19 lines of output]
Traceback (most recent call last):
File "C:UsersAdministratorAppDataLocalProgramsPythonPython39lib
site-packagespip_vendorpyproject_hooks_in_process_in_process.py", line 353,
in <module>
main()
File "C:UsersAdministratorAppDataLocalProgramsPythonPython39lib
site-packagespip_vendorpyproject_hooks_in_process_in_process.py", line 335,
in main
json_out['return_val'] = hook(**hook_input['kwargs'])
File "C:UsersAdministratorAppDataLocalProgramsPythonPython39lib
site-packagespip_vendorpyproject_hooks_in_process_in_process.py", line 118,
in get_requires_for_build_wheel
return hook(config_settings)
File "C:UsersAdministratorAppDataLocalTemp2pip-build-env-m26e9hf4
overlayLibsite-packagessetuptoolsbuild_meta.py", line 325, in get_requires_
for_build_wheel
return self._get_build_requires(config_settings, requirements=['wheel'
])
File "C:UsersAdministratorAppDataLocalTemp2pip-build-env-m26e9hf4
overlayLibsite-packagessetuptoolsbuild_meta.py", line 295, in _get_build_re
quires
self.run_setup()
File "C:UsersAdministratorAppDataLocalTemp2pip-build-env-m26e9hf4
overlayLibsite-packagessetuptoolsbuild_meta.py", line 480, in run_setup
super(_BuildMetaLegacyBackend, self).run_setup(setup_script=setup_scri
pt)
File "C:UsersAdministratorAppDataLocalTemp2pip-build-env-m26e9hf4
overlayLibsite-packagessetuptoolsbuild_meta.py", line 311, in run_setup
exec(code, locals())
File "<string>", line 3, in <module>
File "C:UsersAdministratorAppDataLocalTemp2pip-install-pg6_kfalu
wsgi_05f18753100a4e25a475b36504fbabe5uwsgiconfig.py", line 8, in <module>
uwsgi_os = os.uname()[0]
AttributeError: module 'os' has no attribute 'uname'
[end of output]
note: This error originates from a subprocess, and is likely not a problem wit
h pip.
error: subprocess-exited-with-error
× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.
note: This error originates from a subprocess, and is likely not a problem with
pip.
gunicorn的错误出现在我试图使用它运行flask项目的时候
User
C:UsersAdministratorDesktop******>gunicorn -w 4 -t 30 -b 0.0.0.0
:5000 app:index
Traceback (most recent call last):
File "C:UsersAdministratorAppDataLocalProgramsPythonPython39librunpy.
py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:UsersAdministratorAppDataLocalProgramsPythonPython39librunpy.
py", line 87, in _run_code
exec(code, run_globals)
File "C:UsersAdministratorAppDataLocalProgramsPythonPython39Scriptsgu
nicorn.exe__main__.py", line 4, in <module>
File "C:UsersAdministratorAppDataLocalProgramsPythonPython39libsite-p
ackagesgunicornappwsgiapp.py", line 9, in <module>
from gunicorn.app.base import Application
File "C:UsersAdministratorAppDataLocalProgramsPythonPython39libsite-p
ackagesgunicornappbase.py", line 11, in <module>
from gunicorn import util
File "C:UsersAdministratorAppDataLocalProgramsPythonPython39libsite-p
ackagesgunicornutil.py", line 8, in <module>
import fcntl
ModuleNotFoundError: No module named 'fcntl'
它们的运行或安装无一例外都是需要UNIX/Linux,都是默认在 UNIX/Linux 上运行,因此选择 Waitress作为windows上的服务器是最好的选择
nginx.exe 启动nginx
nginx.exe -t 检查conf配置有没有问题
nginx.exe -s stop 停止nginx
nginx.exe -s reload 更新nginx
4. Waitress命令
waitress-serve --host=0.0.0.0 --port=5000 myapp:application
如果您的 Flask 应用程序在名为 的文件中定义myapp.py
,并且 WSGI 应用程序对象名为application
5.开始!
2.启动它
3.使用 Waitress与它绑定并监视来自nginx的请求
waitress-serve --host=0.0.0.0 --port=5000 myapp:application
server {
listen 8080; # 修改为您的所需端口
server_name localhost;
location / {
# 允许所有请求方法,包括 POST
allow all;
proxy_pass ****; # 更改为您的Flask应用程序的主机和端口
}
location /static/ {
root ******;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
nginx.exe 启动nginx
nginx.exe -t 检查conf配置有没有问题
nginx.exe -s reload 更新nginx
nginx.exe -s stop 停止nginx
nginx.exe 启动nginx
原文地址:https://blog.csdn.net/m0_56366541/article/details/134750816
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.7code.cn/show_49172.html
如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除!