Код: Выделить всё
current_directory = os.path.dirname(os.path.abspath(__file__))
templates_directory = os.path.join(current_directory, "templates")
static_directory = os.path.join(current_directory, "static")
app = FastAPI(openapi_url="/openapi.json")
app.mount("/templates", StaticFiles(directory=templates_directory), name="templates")
app.mount("/static", StaticFiles(directory=static_directory), name="static")
Код: Выделить всё
[*]
HTTP-часть конфигурации nginx выглядит так: вот так:
Код: Выделить всё
http {
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;
tcp_nopush on;
keepalive_timeout 65;
types_hash_max_size 4096;
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
server {
listen 80;
server_name mywebsite.com www.mywebsite.com;
# Redirect all HTTP requests to HTTPS
return 301 https://$host$request_uri;
}
server {
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/mywebsite.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/mywebsite.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
location / {
proxy_pass http://127.0.0.1:8000;
proxy_http_version 1.1;
proxy_set_header Host $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;
}
# Add the static location block here for both HTTP and HTTPS
location /static/ {
alias /app/app/static/;
try_files $uri $uri/ =404;
}
}
# This server block is automatically added by Certbot for redirection
server {
listen 80;
server_name mywebsite.com www.mywebsite.com;
if ($host = mywebsite.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
return 404; # managed by Certbot
}
}
- Я проверил правильные разрешения для файла.
- Пытался переименовать и переместить в другие каталоги, чтобы проверить, не являются ли проблемой права доступа к каталогу.
- Проверено завершающий и не завершающий / в конфигурации nginx
Подробнее здесь: https://stackoverflow.com/questions/792 ... https-when
Мобильная версия