Skip to content

nvminh1602/nginx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 

Repository files navigation

Có. Cấu hình chuẩn nên là:

Vercel frontendhttps://backend-aurora-hotel.nvminh162.id.vnCloudflareEC2 Nginx 443/80backend container :8080

Đừng gọi trực tiếp http://IP:8080 nữa vì Vercel là HTTPS sẽ bị Mixed Content.

Cloudflare DNS Trong Cloudflare DNS giữ record như ảnh là đúng:

Type: A
Name: backend-aurora-hotel
Content: 52.220.0.146
Proxy status: Proxied
TTL: Auto

EC2 Security Group Mở inbound:

HTTP  80   0.0.0.0/0
HTTPS 443  0.0.0.0/0

Có thể đóng public 8080 sau khi Nginx proxy ổn.

Cài Nginx Trên EC2

sudo apt update
sudo apt install -y nginx

Tạo config:

sudo nano /etc/nginx/sites-available/backend-aurora-hotel

Nội dung:

server {
    listen 80;
    server_name backend-aurora-hotel.nvminh162.id.vn;

    location / {
        proxy_pass http://127.0.0.1:8080;
        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;

        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}

Enable:

sudo ln -s /etc/nginx/sites-available/backend-aurora-hotel /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx

Sau đó test:

curl http://backend-aurora-hotel.nvminh162.id.vn/api/v1/branches/public/active?page=0&size=100

Cloudflare SSL Vào Cloudflare → SSL/TLSOverview:

Ban đầu chọn:

Flexible

Cách này nhanh nhất vì Cloudflare nhận HTTPS từ browser, rồi gọi HTTP port 80 tới Nginx.

Sau khi chạy ổn, nếu muốn chuẩn hơn thì đổi sang Full (strict) và cài Cloudflare Origin Certificate trên Nginx.

Vercel Frontend Vào Vercel project → SettingsEnvironment Variables, đặt:

VITE_API_BASE_URL=https://backend-aurora-hotel.nvminh162.id.vn

Sau đó redeploy frontend.

Backend .env Trên EC2, nhớ cho phép origin Vercel:

ALLOWED_ORIGINS=https://aurora-hotel-management-system.vercel.app,http://localhost:5173

Rồi restart backend:

cd /home/ubuntu/aurora-hotel-management-system/aurora-backend
docker compose up -d --pull always --force-recreate

Kết quả mong muốn: frontend gọi API dạng HTTPS:

https://backend-aurora-hotel.nvminh162.id.vn/api/v1/branches/public/active

Không còn Mixed Content nữa.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors