Setup Nginx
Requirements:
- OS Ubuntu 22.04
- Domain: exp erp.alrasyid.live
- Study case server Odoo
- Odoo berjalan di port 8069 -> atau custom port
- Service Odoo sedang running
Basic Steps
1. Install Nginx
Install
sudo apt update
sudo apt install nginx -y
Cek status nginx
sudo systemctl status nginx
Jika aktif, coba akses
http://IPVPS:PORT
2. Configuration Firewall
Jika firewall aktif, harus mengizinkan trafik HTTP atau HTTPS terlebih dahulu
sudo ufw allow 'Nginx Full'
3. Buat Konfigurasi Nginx
Buat file konfigurasi baru
sudo nano /etc/nginx/sites-available/odoo
Opsi konfigurasi nginx (sesuaikan dengan kebutuhan)
- Opsi A
Reverse proxy (Untuk python app, node.js, odoo dsb)
server {
listen 80;
server_name www.erp.alrasyid.live erp.alrasyid.live;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2;
server_name www.erp.alrasyid.live erp.alrasyid.live;
add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload";
add_header X-Frame-Options SAMEORIGIN;
add_header X-Content-Type-Options nosniff;
client_max_body_size 100M;
location / {
proxy_pass http://127.0.0.1:YOUR_PORT;
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 https;
proxy_http_version 1.1;
proxy_set_header Connection "";
}
location /longpolling/ {
proxy_pass http://127.0.0.1:8831;
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 https;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
# Error pages
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
}
- Opsi B
Web statis (HTML/JS/CSS biasa)
server {
listen 80;
server_name erp.alrasyid.live www.erp.alrasyid.live;
# Location folder code/html
root /var/www/erp-alrasyide;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}4. Aktifkan Konfigurasi Nginx
Aktifkan konfigurasi Nginx
sudo ln -s /etc/nginx/sites-available/odoo /etc/nginx/sites-enabled/
Test konfigurasi
sudo nginx -t
Jika hasilnya seperti ini, berhasil
syntax is ok
test is successful
Restart nginx
sudo systemctl restart nginx
Akses domain (contoh)
http://erp.alrasyid.live
5. Install Certbot (SSL Gratis)
Certbot adalah client resmi dari Let's Encrypt untuk generate SSL gratis.
Install
sudo apt install certbot python3-certbot-nginx -y
Cek Versi
certbot --version
6. Generate SSL Certbot
Generate SSL otomatis
sudo certbot --nginx -d erp.alrasyid.live
Ikuti instruksi
- Masukkan email (untuk notifikasi renewal urgent).
- Setujui Terms of Service (A).
- Saat ditanya tentang Redirect, pilih 2 (Redirect - Make all requests redirect to secure HTTPS access). Ini direkomendasikan.
7. Auto Renewal SSL
Cek auto renewal
sudo systemctl status certbot.timer
Test renew manual
sudo certbot renew --dry-run
8. Setting Configuration Odoo agar lebih aman
Edit odoo.conf
sudo nano /etc/odoo/odoo.conf
Tambahkan
proxy_mode = True
9. Security Hardening (Optional - Tambahan)
Tambahkan di configuration nginx
add_header X-Frame-Options SAMEORIGIN;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
Arsitektur akhir:
User → HTTPS → Nginx → Odoo (8069)
Nginx:
Handle SSL
Reverse proxy
Security header
Compression
Load balancing (kalau pakai workers)