server {
    listen 443 ssl http2; # 开启 http2
    server_name memos.ryantech.ltd; # 配置为您需要的域名

    ssl_certificate cert/memos.ryantech.ltd.pem;
    ssl_certificate_key cert/memos.ryantech.ltd.key;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_prefer_server_ciphers on;

    ssl_stapling on; # 开启 ssl stapling
    ssl_stapling_verify on;
    ssl_trusted_certificate cert/memos.ryantech.ltd.pem; # 和 ssl_certificate 保持一致

    add_header Strict-Transport-Security "max-age=31536000"; # HSTS 设置

    # 开启 gzip 压缩，降低对带宽的占用
    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;

    # 配置反向代理
    location / {
        proxy_redirect off;
        proxy_pass http://127.0.0.1:5230; # 端口设置为 memos container 对外开放的端口
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        client_max_body_size 4096M; # 允许上传的文件的最大大小，这里设置为 4GB
    }
}

# 配置 https 跳转
server {
    listen 80;
    server_name memos.ryantech.ltd;
    rewrite ^(.*)$ https://$host$1; # 将所有 HTTP 请求通过 rewrite 指令重定向到 HTTPS
}