Answer the question
In order to leave comments, you need to log in
How to connect HTTPS to NGINX + Gunicorn + Flask?
There is a VPS with several sites on Flask, nginx config:
server {
listen 80;
server_name sitename.ru www.sitename.ru;
location /.well-known {
root /home/username/sites/sitename.ru/flask_app/templates;
}
location / {
include proxy_params;
proxy_pass http://unix:/home/username/sites/sitename.ru/flask_app/sitename.sock;
}
}
# wildcard route for ssl verification
@app.route('/', defaults={'path': ''})
@app.route('/.well-known/<path:path>')
def ssl_cert(path):
return render_template('.well-known/' + path)
sudo certbot certonly --dry-run -d sitename.ru -d www.sitename.ru
Saving debug log to /var/log/letsencrypt/letsencrypt.log
How would you like to authenticate with the ACME CA?
-------------------------------------------------------------------------------
1: Nginx Web Server plugin - Alpha (nginx)
2: Spin up a temporary webserver (standalone)
3: Place files in webroot directory (webroot)
-------------------------------------------------------------------------------
Select the appropriate number [1-3] then [enter] (press 'c' to cancel): 3
Plugins selected: Authenticator webroot, Installer None
Starting new HTTPS connection (1): acme-staging-v02.api.letsencrypt.org
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for sitename.ru
http-01 challenge for www.sitename.ru
Input the webroot for sitename.ru: (Enter 'c' to cancel): /home/username/sites/sitename.ru/flask_app/templates/.well-known
Select the webroot for www.sitename.ru:
-------------------------------------------------------------------------------
1: Enter a new webroot
2: /home/username/sites/sitename.ru/flask_app/templates/.well-known
-------------------------------------------------------------------------------
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2
Waiting for verification...
Cleaning up challenges
Failed authorization procedure. www.sitename.ru (http-01): urn:ietf:params:acme:error:unauthorized :: The client lacks sufficient authorization :: Invalid response from http://www.sitename.ru/.well-known/acme-challenge/2E4cltwPGNZR-Z5lJZfYES5q0fQPCyg6mbtaJNccp-A: "\ufeff<!DOCTYPE html>
<meta charset="utf-8">
<html lang="ru">
<head>
<title>\u041e\u0410\u041e \xab\u0411\u0430\u0437\u043e\u0432\u044b\u0435 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0438\xbb ", sitename.ru (http-01): urn:ietf:params:acme:error:unauthorized :: The client lacks sufficient authorization :: Invalid response from http://sitename.ru/.well-known/acme-challenge/ipbROalh3pstmv_4wA0EzgO0nu8zAk3Hf06k0Wu8bYc: "\ufeff<!DOCTYPE html>
<meta charset="utf-8">
<html lang="ru">
<head>
<title>\u041e\u0410\u041e \xab\u0411\u0430\u0437\u043e\u0432\u044b\u0435 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0438\xbb "
IMPORTANT NOTES:
- The following errors were reported by the server:
Domain: www.sitename.ru
Type: unauthorized
Detail: Invalid response from
http://www.sitename.ru/.well-known/acme-challenge/2E4cltwPGNZR-Z5lJZfYES5q0fQPCyg6mbtaJNccp-A:
"<!DOCTYPE html>
<meta charset="utf-8">
<html lang="ru">
<head>
<title>Welcome to site "
Domain: sitename.ru
Type: unauthorized
Detail: Invalid response from
http://sitename.ru/.well-known/acme-challenge/ipbROalh3pstmv_4wA0EzgO0nu8zAk3Hf06k0Wu8bYc:
"<!DOCTYPE html>
<meta charset="utf-8">
<html lang="ru">
<head>
<title>Welcome to site "
To fix these errors, please make sure that your domain name was
entered correctly and the DNS A/AAAA record(s) for that domain
contain(s) the right IP address.
Answer the question
In order to leave comments, you need to log in
Everything is done using nginx.
server {
listen 443 ssl http2;
keepalive_timeout 70;
server_name ...;
ssl_certificate /etc/letsencrypt/live/.../fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/.../privkey.pem;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
ssl_prefer_server_ciphers on;
ssl_dhparam /etc/nginx/dhpdo.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
add_header Strict-Transport-Security "max-age=31536000; includeSubdomains;";
add_header Access-Control-Allow-Origin *;
location / {
uwsgi_pass unix:///run/uwsgi/app/path/socket;
include uwsgi_params;
uwsgi_read_timeout 600;
}
location /static/ {
alias /var/web/static/;
expires 30h; # кешируем в браузере на 30 часов
}
location /.well-known/ {
alias /tmp/.well-known/;
expires 0;
}
access_log /var/log/nginx/name.access.log;
error_log /var/log/nginx/name.error.log;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question