【问题标题】:NGINX server running FLASK on Raspberry Pi在 Raspberry Pi 上运行 FLASK 的 NGINX 服务器
【发布时间】:2020-04-21 22:24:20
【问题描述】:

我正在尝试在 Pi Model 3B+ 上使用 NGINX 服务器运行烧瓶应用程序。目录 /home/pi/api/api.py 中的代码。我正在关注这篇文章 https://www.raspberrypi-spy.co.uk/2018/12/running-flask-under-nginx-raspberry-pi/

我的 WSGI ini 文件

[uwsgi]
chdir = /home/pi/api
module = api:app

master = true
processes = 1
threads = 2

uid = www-data
gid = www-data

socket = /tmp/api.sock
chmod-socket = 664
vacuum = true

删除默认值后我的 uwsgi 代理

sudo nano /etc/nginx/sites-available/api_proxy
server {
listen 80;
server_name localhost;

location / { try_files $uri @app; }
location @app {
include uwsgi_params;
uwsgi_pass unix:/tmp/api.sock;
}
}

我的 uwsgi.service 文件

[Unit]
Description=uWSGI Service
After=network.target

[Service]
User=www-data
Group=www-data
WorkingDirectory=/home/pi/flasktest/
ExecStart=/usr/local/bin/uwsgi --ini /home/pi/api/uwsgi.ini

[Install]
WantedBy=multi-user.target

但是当我使用启动服务器时

sudo systemctl status uwsgi.service

我收到此错误

uwsgi.service - uWSGI Service
   Loaded: loaded (/etc/systemd/system/uwsgi.service; enabled; vendor preset: enabled)
   Active: active (running) since Wed 2020-04-22 02:58:37 IST; 51min ago
 Main PID: 464 (uwsgi)
    Tasks: 3 (limit: 2319)
   Memory: 13.5M
   CGroup: /system.slice/uwsgi.service
           ├─464 /usr/local/bin/uwsgi --ini /home/pi/api/uwsgi.ini
           └─728 /usr/local/bin/uwsgi --ini /home/pi/api/uwsgi.ini

Apr 22 03:40:32 websync uwsgi[464]:   File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
Apr 22 03:40:32 websync uwsgi[464]:   File "<frozen importlib._bootstrap_external>", line 724, in exec_module
Apr 22 03:40:32 websync uwsgi[464]:   File "<frozen importlib._bootstrap_external>", line 859, in get_code
Apr 22 03:40:32 websync uwsgi[464]:   File "<frozen importlib._bootstrap_external>", line 916, in get_data
Apr 22 03:40:32 websync uwsgi[464]: PermissionError: [Errno 13] Permission denied: './api.py'
Apr 22 03:40:32 websync uwsgi[464]: unable to load app 0 (mountpoint='') (callable not found or import error)
Apr 22 03:40:32 websync uwsgi[464]: *** no app loaded. going in full dynamic mode ***
Apr 22 03:40:32 websync uwsgi[464]: *** uWSGI is running in multiple interpreter mode ***
Apr 22 03:40:32 websync uwsgi[464]: gracefully (RE)spawned uWSGI master process (pid: 464)
Apr 22 03:40:32 websync uwsgi[464]: spawned uWSGI worker 1 (pid: 728, cores: 2)

请帮助。

【问题讨论】:

    标签: python nginx flask raspberry-pi uwsgi


    【解决方案1】:

    错误提示UWSGI没有访问api.py文件的权限。根据您的配置,UWSGI 使用用户和组 www-data 运行。检查该用户或组是否至少对该文件具有读取权限。

    顺便说一句,除非您需要 nginx 的某些功能(证书处理、多个并发连接、静态文件的快速响应时间或其他一些功能),否则您可以消除 nginx 和 UWSGI 并少得多担心。如果这将是一个面向公众的服务器,那么是的,继续你的路线。但如果这是一些带有简单 Web 界面的私人设备,请消除复杂性。

    【讨论】:

    • 感谢您的回答。是的,我的烧瓶 api 上需要 ssl,所以我使用的是 NGINX 网络服务器。你能告诉我如何读取和更改文件的权限吗?
    • ls -l api.py 将显示文件权限、所有者和组。 chmod 允许您更改您具有写入权限的文件的权限。 chownchrgp 允许您分别更改文件的所有者和组。有关这些命令和其他命令的更多信息,请参见系统手册页。 (man chmodman lsman chown 等)
    猜你喜欢
    • 2020-01-21
    • 2020-06-29
    • 1970-01-01
    • 1970-01-01
    • 2020-06-18
    • 1970-01-01
    • 2021-11-12
    • 2017-04-11
    • 1970-01-01
    相关资源
    最近更新 更多