AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题

问题[flask](server)

Martin Hope
KiDo
Asked: 2021-10-01 02:30:09 +0800 CST

source venv/bin/activate 在 CentOS 上没有返回任何东西

  • 2

我正在尝试在 CentOS 上部署 Python Flask 应用程序(用于 API 端点)以进行工作,但我遵循的每个在线指南都不适合我!

python3 -m venv APIenv

环境已成功创建,但随后尝试激活它:

源 APIenv/bin/激活

什么都不返回,既不是错误也不是激活它!

据我了解,激活它应该使 CLI 看起来像这样:

(venv) $ _

我还有一个问题:

pip3 安装 firebase_admin

这有效并且已安装,但随后运行我的应用程序:

python3 应用程序.py

回溯(最后一次调用):文件“app.py”,第 4 行,在 import firebase_admin ModuleNotFoundError:没有名为“firebase_admin”的模块

我遵循的每个在线指南都让我卡在这里,我真的需要让它工作,我做错了什么?

centos python flask
  • 1 个回答
  • 252 Views
Martin Hope
ThatCoolCoder
Asked: 2021-07-25 23:29:22 +0800 CST

为什么 Apache2 找不到我的 WSGI 应用程序?

  • 2

在我之前的问题中,我询问了如何让 mod_wsgi 使用特定的 Python 版本。根据该问题的答案,我创建了一个 Python 3.9 虚拟环境并让 WSGI 使用它。但是,现在我的 Flask 应用程序根本没有运行——我只是为我的站点的其余部分配置了 404 页面。重新启动 Apache2 时我没有收到任何错误,当我访问该站点时 Apache 错误日志为空。我认为错误一定是由于我的虚拟环境造成的,因为我在使用相同的配置样式之前已经创建了以前的测试 Flask 应用程序。

我的虚拟环境位于path/to/my/app/venv/.

path/to/my/app/runner.wsgi:

import sys

# Make something appear in error log if the WSGI is run at all
raise ValueError()

PROJECT_DIR = os.path.dirname(os.path.realpath(__file__))
sys.path.insert(0, PROJECT_DIR)

from my_app import app as application

部分/etc/apache2/sites-available/000-default-le-ssl.conf:

WSGIDaemonProcess myapp user=www-data group=www-data threads=4 python-home=/path/to/my/app/venv/
WSGIScriptAlias /my-app/ path/to/my/app/runner.wsgi

/etc/apache2/mods-available/wsgi.load

LoadModule wsgi_module "/path/to/my/app/venv/lib/python3.9/site-packages/mod_wsgi/server/mod_wsgi-py39.cpython-39-x86_64-linux-gnu.so"
WSGIPythonHome "path/to/my/app/venv"

操作系统:Ubuntu 18.04.5 LTS

mod-wsgi python http-status-code-404 apache2 flask
  • 2 个回答
  • 447 Views
Martin Hope
G M
Asked: 2021-04-02 08:46:57 +0800 CST

使用 gunicorn 和 Nginx 服务多个套接字会导致 NotFound 错误

  • 0

我正在尝试使用 Nginx 作为反向代理来提供两个 Flask 应用程序。在我default.conf 重新加载的sudo service nginx restart我有:

    location /app2loc/ {
            include proxy_params;
            proxy_pass http://unix:/var/www/html/app2/app.sock;
    }
    location / {
            include proxy_params;
            proxy_pass http://unix:/var/www/html/app1/app.sock;
    }

当app1我在www.mydomain.com. 第二个应用程序app2似乎运行有任何错误作为证据,这是输出sudo systemctl status app2.service:

● app2.service - Gunicorn instance to serve Flask app2.
   Loaded: loaded (/etc/systemd/system/capitcatalog.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2021-04-01 18:11:28 CEST; 26min ago
 Main PID: 24762 (gunicorn)
    Tasks: 25 (limit: 4423)
   CGroup: /system.slice/capitcatalog.service
           ├─24762 /var/www/html/app2/env/bin/python3.6 /var/www/html/app2/env/bin/gunicorn --chdir /var/www/html/app2/ -w 3 -b unix:app.sock -m 007 
           ├─24778 /var/www/html/app2/env/bin/python3.6 /var/www/html/app2/env/bin/gunicorn --chdir /var/www/html/app2/ -w 3 -b unix:app.sock -m 007 
           ├─24779 /var/www/html/app2/env/bin/python3.6 /var/www/html/app2/env/bin/gunicorn --chdir /var/www/html/app2/ -w 3 -b unix:app.sock -m 007 
           └─24780 /var/www/html/app2/env/bin/python3.6 /var/www/html/app2/env/bin/gunicorn --chdir /var/www/html/app2/ -w 3 -b unix:app.sock -m 007

但是,当我尝试使用它访问它时,www.mydomain.com/app2loc我有一个

Not Found
The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.

我想知道可能是什么错误。为什么第二个套接字似乎无法访问?

这是的输出nginx -T:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
# configuration file /etc/nginx/nginx.conf:
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # SSL Settings
    ##

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    #include /etc/nginx/sites-enabled/*;

    # ADDED FOR UV VIEWR
    proxy_cache_key $scheme$proxy_host$uri;
    fastcgi_cache_key "$scheme$host$uri";


}


#mail {
#   # See sample authentication script at:
#   # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
# 
#   # auth_http localhost/auth.php;
#   # pop3_capabilities "TOP" "USER";
#   # imap_capabilities "IMAP4rev1" "UIDPLUS";
# 
#   server {
#       listen     localhost:110;
#       protocol   pop3;
#       proxy      on;
#   }
# 
#   server {
#       listen     localhost:143;
#       protocol   imap;
#       proxy      on;
#   }
#}

# configuration file /etc/nginx/modules-enabled/50-mod-http-geoip.conf:
load_module modules/ngx_http_geoip_module.so;

# configuration file /etc/nginx/modules-enabled/50-mod-http-image-filter.conf:
load_module modules/ngx_http_image_filter_module.so;

# configuration file /etc/nginx/modules-enabled/50-mod-http-xslt-filter.conf:
load_module modules/ngx_http_xslt_filter_module.so;

# configuration file /etc/nginx/modules-enabled/50-mod-mail.conf:
load_module modules/ngx_mail_module.so;

# configuration file /etc/nginx/modules-enabled/50-mod-stream.conf:
load_module modules/ngx_stream_module.so;

# configuration file /etc/nginx/mime.types:

types {
    text/html                             html htm shtml;
    text/css                              css;
    text/xml                              xml;
    image/gif                             gif;
    image/jpeg                            jpeg jpg;
    application/javascript                js;
    application/atom+xml                  atom;
    application/rss+xml                   rss;

    text/mathml                           mml;
    text/plain                            txt;
    text/vnd.sun.j2me.app-descriptor      jad;
    text/vnd.wap.wml                      wml;
    text/x-component                      htc;

    image/png                             png;
    image/tiff                            tif tiff;
    image/vnd.wap.wbmp                    wbmp;
    image/x-icon                          ico;
    image/x-jng                           jng;
    image/x-ms-bmp                        bmp;
    image/svg+xml                         svg svgz;
    image/webp                            webp;

    application/font-woff                 woff;
    application/java-archive              jar war ear;
    application/json                      json;
    application/mac-binhex40              hqx;
    application/msword                    doc;
    application/pdf                       pdf;
    application/postscript                ps eps ai;
    application/rtf                       rtf;
    application/vnd.apple.mpegurl         m3u8;
    application/vnd.ms-excel              xls;
    application/vnd.ms-fontobject         eot;
    application/vnd.ms-powerpoint         ppt;
    application/vnd.wap.wmlc              wmlc;
    application/vnd.google-earth.kml+xml  kml;
    application/vnd.google-earth.kmz      kmz;
    application/x-7z-compressed           7z;
    application/x-cocoa                   cco;
    application/x-java-archive-diff       jardiff;
    application/x-java-jnlp-file          jnlp;
    application/x-makeself                run;
    application/x-perl                    pl pm;
    application/x-pilot                   prc pdb;
    application/x-rar-compressed          rar;
    application/x-redhat-package-manager  rpm;
    application/x-sea                     sea;
    application/x-shockwave-flash         swf;
    application/x-stuffit                 sit;
    application/x-tcl                     tcl tk;
    application/x-x509-ca-cert            der pem crt;
    application/x-xpinstall               xpi;
    application/xhtml+xml                 xhtml;
    application/xspf+xml                  xspf;
    application/zip                       zip;

    application/octet-stream              bin exe dll;
    application/octet-stream              deb;
    application/octet-stream              dmg;
    application/octet-stream              iso img;
    application/octet-stream              msi msp msm;

    application/vnd.openxmlformats-officedocument.wordprocessingml.document    docx;
    application/vnd.openxmlformats-officedocument.spreadsheetml.sheet          xlsx;
    application/vnd.openxmlformats-officedocument.presentationml.presentation  pptx;

    audio/midi                            mid midi kar;
    audio/mpeg                            mp3;
    audio/ogg                             ogg;
    audio/x-m4a                           m4a;
    audio/x-realaudio                     ra;

    video/3gpp                            3gpp 3gp;
    video/mp2t                            ts;
    video/mp4                             mp4;
    video/mpeg                            mpeg mpg;
    video/quicktime                       mov;
    video/webm                            webm;
    video/x-flv                           flv;
    video/x-m4v                           m4v;
    video/x-mng                           mng;
    video/x-ms-asf                        asx asf;
    video/x-ms-wmv                        wmv;
    video/x-msvideo                       avi;
}

# configuration file /etc/nginx/conf.d/default.conf:

server {
        server_name www.mydomain.com;
        listen 80;
        root /var/www/html/;

    # this is working properly 
    location /vrt/ {
            alias /var/www/html/vrt/; 
        }

    location /app2/ {
                include proxy_params;
                proxy_pass http://unix:/var/www/html/app2/app.sock;
        }

}        

# configuration file /etc/nginx/proxy_params:
proxy_set_header Host $http_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-Proto $scheme;
nginx socket gunicorn flask
  • 1 个回答
  • 205 Views
Martin Hope
Amaimersion
Asked: 2021-02-05 07:06:43 +0800 CST

pymongo + flask + gunicorn:“connect=False”时第一次操作前“Authentication failed”

  • 0

我正在使用 MongoDB Atlas。我有这个 URL 用于连接:mongodb+srv://<LOGIN>:<PASSWORD>@<URL>/<DB>?retryWrites=true&w=majority&authSource=admin。

我正在使用这个堆栈:flask、gunicorn、pymongo、mongoengine(我不认为它是相关的,因为 mongoengine 实际上使用 pymongo)。

独角兽配置:

  • 同步工作者,
  • 线程 = 1,
  • 工人数 = 8

连接时,我正在使用,connect=False因为 pymongo 本身不是分叉安全的。connect=False它将在第一次操作之前连接到数据库。它需要设置为False,因为 gunicorn 使用 pre-fork 模型。

但我面临以下情况:

  1. 在第一次请求(端点进行一些数据库操作)时,我收到此错误:pymongo.errors.OperationFailure: Authentication failed., full error: {'ok': 0, 'errmsg': 'Authentication failed.', 'code': 8000, 'codeName': 'AtlasError'}
  2. 在第二次请求时,一切都很好(即,数据库操作已成功完成)。
  3. 如果你按F5多次,那么有时你会出现“验证失败”的错误,有时一切都会好起来的。

如果我准备好connect=True了,一切都会好起来的。我从未见过此“身份验证失败”错误。

但后来我收到了这个警告信息:UserWarning: MongoClient opened before fork. Create MongoClient only after forking. See PyMongo's documentation for details: https://pymongo.readthedocs.io/en/stable/faq.html#is-pymongo-fork-safe。

所以,显然,connect需要设置为False.

我接受了两名工人的测试。看起来会出现这种情况:

  1. 假设我有两个具有以下 pid 的 gunicorn 同步工作者:22429 和 22430。
  2. 我收到请求。工人 22429 处理它。一切都很好,因为它是第一个工作人员,看起来它成功地建立了数据库连接。
  3. 我按 F5,工人 22429 再次处理它,一切都很好。
  4. 我再次按 F5,现在工人 22430 处理它。它会引发错误“身份验证失败”。
  5. 我再次按 F5,工人 22430 处理它。现在一切都很好,因为那个工人已经建立了联系。
  6. 现在,我所有的工人(我只有两个)都连接到数据库。无论我按 F5 多少次,每个请求都会成功完成。

但为什么它发生在第一次请求上?来自 pymongo:“如果 connect=False,则在第一次操作时连接。”。如果我理解正确,pymongo 应该在实际第一次操作之前连接,成功完成连接,然后才执行该操作。

那为什么我的第一个数据库操作对每个工人都失败了?我应该如何处理这个?

gunicorn mongodb flask
  • 1 个回答
  • 916 Views
Martin Hope
posop
Asked: 2020-07-22 23:01:54 +0800 CST

由 nginx uwsgi 服务的烧瓶应用程序返回 502

  • 0

我无法连接到由 nginx 和 uwsgi 提供的烧瓶应用程序(searx 搜索引擎)。

我的网络服务器显示“502 Bad Gateway nginx”

这是我的 nginx 错误:错误日志:/var/log/nginx/error.log

[crit] 2688#2688: *4 connect() to unix:/run/uwsgi/app/searx/socket.sock failed 
(2: No such file or directory) while connecting to upstream,
client: 216.186.XXX.XXX, server searx.mysite.com, 
request: "GET / HTTP/1.1", 
upstream: "uwsgi://unix:/run/uwsgi/app/searx/socket.sock:", 
host: "searx.mysite.com"

所以我可以看到socket.sock和上游不一样。

这是我的 nginx.conf

user http;
worker_processes auto;
worker_cpu_affinity auto;

events {
    multi_accept on;
    worker_connections 1024;
}

http {
    charset utf-8;
    sendfile on;
    tcp-nopush on;
    tcp_nodelay on;
    server_tokens off;
    log_not_found off;
    types_hash_max_size 4096;
    client_max_body_size 16M;

    include mime.types;
    default_type application/octet-stream;

    keepalive_timeout 65;

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log warn;

    include /etc/nginx/sites-enabled/*;
}

这是我的 searx.conf,我指定 .sock 文件所在的唯一位置:

/etc/nginx/sites-enabled/searx.conf

server {
    listen 80;
    server_name searx.mysite.com;
    
    location / {
        include uwsgi_params;
        uwsgi_pass unix:/run/uwsgi/app/searx/socket.sock;
    }
    
    root /usr/local/searx/searx-src/searx;
    location /static { }
}

当我查看我的套接字文件夹时,那里没有文件......

ls -alh /run/uwsgi/app/searx/
total 0
drwxr-xr-x 2 searx searx 40 Jul 22 05:02 .
drwxr-xr-x 3 root  root  60 Jul 22 05:02 ..

我用来运行 uwsgi 的命令是:

exec chpst -u http env LC_ALL=en_US.UTF-8 /usr/bin/uwsgi --master --die-on-term --emperor /etc/uwsgi/sites

我用来运行 nginx 的命令:

exec chpst -u root /usr/bin/nginx -c /etc/nginx/nginx.conf -g "daemon off;"

这是我的 searx uwsgi 文件

/etc/uwsgi/sites/searx.ini

[uwsgi]
project = searx
uid = searx
gid = searx
base = /usr/local/searx/searx-src

chdir = %(base)/%(project)
env = SEARX_SETTINGS_PATH=/etc/searx/settings.yml

disable-logging = false
workers = 2

chmod-socket = 666
vacuum = true

single-interpreter = true
master = true
plugin = python
lazy-apps = true
enable-threads = true

module = searx.webapp

route-run = fixpathinfo:

virtualenv = /usr/local/searx/searx-pyenv
pythonpath = %(base)

# NOTE: if I add or delete the next line there is no difference in output
socket = /run/uwsgi/app/searx/socket.sock

更多挖掘:在我设置的 searx.ini中,在日志disable-logging = false中找到了这个:/var/log/uwsgi/current

thunder lock: disabled (you can enable it with --thunder-lock
bind(): Permission denied [core/socket.c line 230]
Wed July 22 15:05:31 2020 - [emperor] curse the uwsgi instance searx.ini (pid: 3320)
Wed July 22 15:05:31 2020 - [emperor] removed uwsgi instance searx.ini

所以我的 searx.ini 或者我怎么称呼它肯定有问题?

我不确定您可能需要哪些其他信息,但很高兴根据需要更新问题。我已经在这几天了,所以我非常感谢你能提供的任何帮助。

nginx uwsgi flask
  • 1 个回答
  • 1804 Views
Martin Hope
ivrin
Asked: 2017-01-25 06:57:58 +0800 CST

如何验证传入请求通过 nginx 转到 gunicorn-flask

  • 0

我正在运行 nginx,gunincorn(启动烧瓶)。当我杀死 nginx 时,nginx 测试页面消失了,但 gunicorn/flask 应用程序继续服务。

  1. 这是预期的吗?
  2. 我如何确保 gunicorn/nginx 一起工作?
  3. 我还检查了 nginx 访问日志,我没有看到对 gunicorn/flask 绑定的端口的请求。

我的过程

  1. 安装 nginx
  2. 安装 gunicorn
  3. 设置 nginx

Nginx 设置

cd /etc/nginx
mkdir sites-available
mkdir sites-enabled
vim /sites-available/my_site
server {
    location / {
        proxy_pass http://localhost:9000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
}
dzdo ln -s ../sites-available/my_site my_site

Nginx 配置文件

user  nginx;
worker_processes  1;
error_log  /var/log/nginx/error.log;
pid        /run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    keepalive_timeout  65;
    include /etc/nginx/conf.d/*.conf;
    index   index.html index.htm;
    server {
        listen       90;
        server_name  localhost;
        root         /usr/share/nginx/html;

        location / {
        }

        error_page  404              /404.html;
        location = /40x.html {
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
        }
    }

    server {
       listen 9001;
       server_name localhost;
       root /tmp/html/;

       location / {
       }
    }
}

独角兽开始

gunicorn –bind 0.0.0.0:9000 “my_site.driver:create_app()” &
nginx gunicorn flask
  • 1 个回答
  • 478 Views
Martin Hope
buddha_buddha
Asked: 2016-11-10 10:53:28 +0800 CST

显示 / 没有 www 的索引,使用 www 正常工作

  • 0

我正在使用 Python、Flask 和 Apache,但我被困住了。当我尝试使用 www 访问我的网站时,它工作正常。但是,当我删除 www 时,该网站显示“/ 的索引”,接下来是一个空的文件列表。我已经阅读了所有可能的解决方案,在我的情况下没有任何效果。我正在使用 WSGI,这意味着 DocumentRoot 无关紧要,因为我使用的是 WSGIScriptAlias 变量。我按照指示使用 ServerAlias - 没有帮助。我在我的 dns 选项中设置了 2 条单独的 A 记录,它们都指向同一个 ip。当我用 www 和不带 www ping 网站时,显示相同的 IP 地址

<VirtualHost *:80>
    ServerName mysite.com
    ServerAlias www.mysite.com
    WSGIScriptAlias / /var/www/mysite/mysite.wsgi
    <Directory /var/www/mysite/mysite/>
        Order allow,deny
        Allow from all
    </Directory>
    Alias /static /var/www/mysite/mysite/app/static
    <Directory /var/www/mysite/mysite/app/static/>
        Order allow,deny
        Allow from all
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/error.log
    LogLevel warn
    CustomLog ${APACHE_LOG_DIR}/access.log combined
... 

</VirtualHost>

有任何想法吗?

这是“apachectl -S”命令的输出:

VirtualHost configuration:
*:80                   is a NameVirtualHost
         default server mysite.com (/etc/apache2/sites-enabled      /000-default.conf:1) 
     port 80 namevhost mysite.com (/etc/apache2/sites-enabled    /000-default.conf:1)
     port 80 namevhost mysite.com (/etc/apache2/sites-enabled    /mysite.conf:1)
             alias www.mysite.com
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex watchdog-callback: using_defaults
Mutex default: dir="/var/lock/apache2" mechanism=fcntl 
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33
domain-name-system python apache-2.4 flask wsgi
  • 1 个回答
  • 262 Views
Martin Hope
Madno
Asked: 2016-09-02 23:37:03 +0800 CST

Nginx 无法将流量传递给 Flask 应用程序和 uwsgi

  • 0

我正在尝试使用 Nginx 部署 Flask 和 uwsgi 应用程序,一切正常,我可以让我的应用程序在我的域上工作:test.example.com:8080.

问题是我无法使其在默认端口 80 下工作,当我尝试浏览时,我从 Nginx 收到以下错误消息test.example.com:

2016/09/02 10:21:29 [error] 2947#2947: *3 no live upstreams while connecting to upstream, client: 75.xxx.xxx.136, server: test.example.com, request: "GET /favicon.ico HTTP/1.1", upstream: "uwsgi://localhost", host: "test.example.com", referrer: "http://test.example.com/"

这是我的 uwsgi 命令:

uwsgi --socket 8080 --chdir /var/www/test.example.com --protocol=http --module myapp:app

这是我的 Nginx 配置:

server {

    listen 80;

    root /var/www/test.example.com;
    server_name test.example.com;

    location / {
        include         uwsgi_params;
        uwsgi_pass   0.0.0.0:8080;
    uwsgi_param SCRIPT_NAME /myapp;
    }
}

Nginx 不能只为我的服务器将流量从 80 传递到端口 8080,我不知道为什么。

nginx uwsgi flask
  • 1 个回答
  • 909 Views
Martin Hope
thaweatherman
Asked: 2016-06-28 04:59:01 +0800 CST

页面未缓存

  • 0

我有一个使用flask+gunicorn在nginx后面运行的简单网络应用程序,并且在某个地方正在缓存页面的陈旧版本。我的 nginx 配置在代理通行证add_header Cache-Control no-cache;的proxy_buffering off;位置。我做了一些搜索,发现 gunicorn 本身并没有缓存任何东西。我的应用程序也没有缓存任何东西,或者至少我没有将它写入。

server { listen 80; server_name mywebsite.com; location / { add_header Cache-Control no-cache; proxy_pass http://127.0.0.1:6789; proxy_set_header Host $host; proxy_buffering off; } }

这就是我正在使用的 nginx 配置,gunicorn 是使用它启动的,gunicorn -b 127.0.0.1:6789 -w 5 app:app并且没有为它设置任何特殊配置。

任何诊断问题的帮助都会很棒。谢谢!

编辑:这是来自返回陈旧页面的请求的响应标头。

Age: 0 Cache-Control: no-cache Connection: Keep-Alive Content-Encoding: gzip Content-Type: text/html; charset=utf-8 Date: Mon, 27 Jun 2016 14:27:29 GMT Server: nginx/1.8.0 Transfer-Encoding: chunked

nginx gunicorn flask
  • 2 个回答
  • 291 Views
Martin Hope
Ali Mezgani
Asked: 2016-06-19 07:07:19 +0800 CST

无法启动 Docker 容器

  • 2

我使用烧瓶、nginx 和 uwsgi 构建了一个图像。

FROM ubuntu:14.04
MAINTAINER Ali Mezgani <[email protected]>

RUN apt-get update && apt-get -y install python python-dev  python-pip
RUN apt-get -y install supervisor
RUN apt-get -y install  nginx

COPY ./app /app

RUN mkdir /var/log/uwsgi/

RUN pip install -r ./app/requirements.txt

RUN rm -fr /etc/nginx/conf.d/*
RUN rm -fr /etc/nginx/sites-enabled/*

COPY app.conf /etc/supervisor/conf.d/app.conf

RUN echo "daemon off;" >> /etc/nginx/nginx.conf
COPY nginx.conf /etc/nginx/sites-enabled/app.conf

expose 80
CMD ["supervisord", "-n"]
CMD ["nginx"]

这是我尝试启动 myapp 容器时得到的输出。

root@cygne:/data/flask# docker start myapp
Error response from daemon: No such container: myapp
Error: failed to start containers: myapp

最后是我拥有的图像的状态。

root@cygne:/data/flask# docker images -a
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
<none>              <none>              91c4b97dc883        10 hours ago        434.1 MB
myapp               latest              3b9dd7cc7006        10 hours ago        434.1 MB
<none>              <none>              28f96039d2da        10 hours ago        434.1 MB
<none>              <none>              dbd7d20bb041        10 hours ago        434.1 MB
<none>              <none>              f29621c65c25        10 hours ago        434.1 MB
<none>              <none>              7d6d99d831c4        10 hours ago        434.1 MB
<none>              <none>              948cc751026f        10 hours ago        434.1 MB
<none>              <none>              afc13c68670c        10 hours ago        434.1 MB
<none>              <none>              90733b74c1ff        10 hours ago        434.1 MB
<none>              <none>              f8252e26afe5        10 hours ago        424.4 MB
<none>              <none>              4b16f8a9bfbb        10 hours ago        424.4 MB
<none>              <none>              126961e5d0b2        10 hours ago        418.6 MB
<none>              <none>              713635425c68        10 hours ago        400.1 MB
<none>              <none>              0755786fa8dc        10 hours ago        396.2 MB
<none>              <none>              3bc29edbc3a3        10 hours ago        188 MB
ubuntu              14.04               8f1bd21bd25c        3 weeks ago         188 MB
mysql               5.7                 2fd136002c22        3 weeks ago         378.4 MB

容器无法启动,我尝试了许多过程,例如清理缓存、重新启动 docker。这是我的系统日志中的内容:

localhost docker[6111]: time="2016-06-18T15:06:12.826760681Z" level=error msg="Handler for GET /v1.23/containers/myapp/json returned error: No such container: myapp"
linux docker containers flask
  • 1 个回答
  • 3169 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve