user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;

include /usr/share/nginx/modules/*.conf;
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;

    types {
        # application/wasm wasm;
        # application/octet-stream dll;
        # application/manifest+json webmanifest;
    }
    server {
        listen 80;
        listen [::]:80;
        server_name localhost;
        return 301 https://$host$request_uri; # Chuyển hướng từ HTTP sang HTTPS
    }

    server {
        listen 443 ssl;
        server_name localhost;

        ssl_certificate /etc/nginx/cert.pem;
        ssl_certificate_key /etc/nginx/key.pem;
        ssl_protocols TLSv1.2 TLSv1.3;
        ssl_ciphers HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers on;

        root /usr/share/nginx/html;
        index index.html;
        location / {
            try_files $uri $uri/ /index.html;
        }

        error_page 404 /index.html; # Đảm bảo các lỗi 404 cũng phục vụ index.html
    }
}