Я развернул приложение flask на nginx, приложение работает просто отлично, но открытие сайта занимает много времени, задержка 5 секунд, прежде чем открывается запрошенная страница.
Вот мои nginx конфигурации:
testapp.service
[Unit]
Description=Gunicorn instance to serve testapp
After=network.target
[Service]
User=pentest
Group=www-data
WorkingDirectory=/home/pentest/testapp
Environment="PATH=/home/pentest/testapp/venv/bin"
ExecStart=/home/pentest/testapp/venv/bin/uwsgi --http :5000 --gevent 10 --master --wsgi-file wsgi.py --callable application
[Install]
WantedBy=multi-user.target
, как вы можете видеть, я использую uwsgi для Запустите приложение, Gevent используется, потому что я планирую использовать socketio позже.
это /site-available/app.config
limit_conn_zone $binary_remote_addr zone=addr:5m;
proxy_cache_path /tmp/cache keys_zone=cache:10m levels=1:2 inactive=600s max_size=100m;
proxy_cache_key "$scheme$request_method$host$request_uri";
server {
server_name website.com;
location / {
include proxy_params;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:5000/;
}
proxy_cache cache;
proxy_cache_valid 200 1s;
}
Это мои nginx .conf конфигурации:
user www-data;
worker_processes 1;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
http {
# Polices add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Proxy-Cache $upstream_cache_status;
# Control Buffer Overflow client_body_buffer_size 10 m;
client_header_buffer_size 10 m;
client_max_body_size 10 m;
large_client_header_buffers 4 10 m;
# Control Timeout
client_body_timeout 15;
client_header_timeout 15;
keepalive_timeout 15;
send_timeout 15;
# Gzip optimize
gzip on;
gzip_comp_level 2;
gzip_min_length 1000;
#gzip_proxied expired no-cache no-store private auth;
gzip_types text / plain application / x-javascript text / xml text / css application / xml;
}