Ubuntu VPS પર પહેલી HTTPS વેબસાઇટ શરૂ કરો
નવા Ubuntu 24.04 VPS પર Nginx અને HTTPS સાથે નાની static વેબસાઇટ શરૂ કરો. અલગ administrator, SSH key, certificate renewal અને reboot પછીની તપાસ આ માર્ગદર્શિકામાં આવરી લેવાય છે. નવી ઍક્સેસ ચકાસાય ત્યાં સુધી ચાલતી ઍક્સેસ ખુલ્લી રાખો.
VPSuntu · અપડેટ: · વાંચવાનો અંદાજિત સમય: 7 મિનિટ
માર્ગદર્શિકાના વિભાગો
સર્વર, domain અને recovery ઍક્સેસ તૈયાર રાખો
Public IPv4, port 22 પર SSH, sudo ચલાવી શકે તેવું શરૂઆતનું account અને તમારા નિયંત્રણમાં હોય તેવો domain ધરાવતો નવો Ubuntu 24.04 VPS લો. Provisioning પહેલાં SSH key બનાવો. ખાલી સર્વર પહેલેથી હોય તો હાલની ઍક્સેસથી key ઉમેરવાનો વિકલ્પ વાપરો. Client commands Linux, macOS અથવા WSLના Bashમાં અને server commands SSH sessionમાં ચલાવવાના છે. ઉદાહરણના paths પર પહેલેથી deployment હોય તો અટકો.
દરેક 203.0.113.10ને તમારા IPથી અને app.example.comને તમારા hostnameથી બદલો; બંને દસ્તાવેજી ઉદાહરણ છે. શરૂઆતના ubuntu accountની જગ્યાએ પ્રદાતાનું સાચું account વાપરો. ઍક્સેસ કે firewall બદલતાં પહેલાં recovery console ખોલો. Image માટે firewallની સૂચનાઓ તપાસો: Oracle Cloud Ubuntu માટે નીચેનો UFW ભાગ લાગુ પડતો નથી.
Provisioning પહેલાં key બનાવો અથવા હાલની ઍક્સેસથી ઉમેરો
તમારા કમ્પ્યુટર પર અલગ key બનાવો અને passphrase આપો. એ નામની file હોય તો બધા પગલાંમાં નવું નામ વાપરો. .pub file જાહેર key છે; private file કમ્પ્યુટર પર જ રાખો.
mkdir -p ~/.ssh
ssh-keygen -t ed25519 -f ~/.ssh/ubuntu_vps
cat ~/.ssh/ubuntu_vps.pubનવા VPS માટે: હવે Ubuntu 24.04 સર્વર બનાવતી વખતે પ્રદાતાના SSH-key fieldમાં આ public key આપો. શરૂઆતનું username તપાસો અને host fingerprint ચકાસવાના પગલાં પર જાઓ. પહેલેથી બનેલા સર્વર માટેના commands છોડો.
પહેલેથી બનેલા ખાલી VPS માટે: ચાલતું SSH session ખુલ્લું રાખો. કમ્પ્યુટરના બીજા terminalમાંથી હાલ કામ કરતી authentication વડે public key મોકલો. existing_vps_keyને હાલની private keyના filenameથી બદલો. Password કે SSH agent વાપરતા હો તો -i ~/.ssh/existing_vps_key છોડો; serverની authentication policy બદલો નહીં.
scp -i ~/.ssh/existing_vps_key ~/.ssh/ubuntu_vps.pub ubuntu@203.0.113.10:ubuntu-vps-admin.pubજૂના server sessionમાં મોકલેલી public-key file તપાસીને શરૂઆતના accountની authorized_keysમાં ઉમેરો. Appendથી જૂની entries જળવાય છે; વધારાની newline છેલ્લી lineમાં newline ન હોય તે સ્થિતિ સંભાળે છે. આ તમારા પોતાના શરૂઆતના account માટે છે. કોઈ ઍક્સેસ ન હોય તો પહેલાં પ્રદાતાની recovery પ્રક્રિયા પૂર્ણ કરો.
if ssh-keygen -lf ~/ubuntu-vps-admin.pub; then
mkdir -p ~/.ssh
chmod 700 ~/.ssh
printf '\n' >> ~/.ssh/authorized_keys
cat ~/ubuntu-vps-admin.pub >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
fiબંને માર્ગમાં, પ્રથમ જોડાણ સ્વીકારતાં પહેલાં trusted recovery consoleમાં યોગ્ય public host keyનો fingerprint મેળવો. Ed25519 host key માટે consoleમાં:
sudo ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pubકમ્પ્યુટરથી નવી key વડે નવું જોડાણ અજમાવો. તે સફળ થાય ત્યાં સુધી જૂની ઍક્સેસ બંધ ન કરો.
ssh -i ~/.ssh/ubuntu_vps ubuntu@203.0.113.10કમ્પ્યુટરના બીજા terminalથી આગળ બનાવવાના અલગ admin માટે public key મોકલો. આ અસ્થાયી public file ફરી મોકલવાથી private key બદલાતી નથી.
scp -i ~/.ssh/ubuntu_vps ~/.ssh/ubuntu_vps.pub ubuntu@203.0.113.10:ubuntu-vps-admin.pubઅલગ administrator બનાવો અને તપાસો
સર્વર પર પહેલાં getent passwd deploy તપાસો. Account મળવું ન જોઈએ. પહેલેથી હોય તો ન વપરાયેલું username પસંદ કરો અને home paths તથા group names સહિત બધે બદલો. આથી બીજા accountની key file બદલાઈ જતી અટકે છે.
Image અને સંસાધનો ચકાસો, upgrades વાંચો અને admin બનાવો. તેના sudo prompts માટે મજબૂત password આપો. Install commands યોગ્ય ownership અને મર્યાદિત permissions ગોઠવે છે.
cat /etc/os-release
free -h
df -h /
sudo apt update
sudo apt upgrade
sudo adduser deploy
sudo usermod -aG sudo deploy
sudo install -d -m 700 -o deploy -g deploy /home/deploy/.ssh
sudo install -m 600 -o deploy -g deploy ~/ubuntu-vps-admin.pub /home/deploy/.ssh/authorized_keysકમ્પ્યુટરના નવા terminalથી નવા admin તરીકે જોડાઓ:
ssh -i ~/.ssh/ubuntu_vps deploy@203.0.113.10આ નવા server sessionમાં sudo ચલાવો. Deployનો password સ્વીકાર્યા પછી root દેખાવું જોઈએ. Login અને sudo બંને ચાલે ત્યારથી આ sessionમાં આગળ વધો; શરૂઆતની ઍક્સેસ ઉપલબ્ધ રાખો.
sudo whoamiNginx અને imageને અનુરૂપ firewall ગોઠવો
સર્વર પર પહેલાં Nginx install કરો. પ્રદાતાનું network firewall અને guest firewall બંને ઍક્સેસને અસર કરે છે. ફેરફાર દરમિયાન recovery console અને ચાલતું SSH session ખુલ્લાં રાખો.
sudo apt install nginx
sudo systemctl enable --now nginxપ્રદાતાના firewallમાં adminના સ્થાનથી TCP 22 અને મુલાકાતીઓ માટે TCP 80/443 મંજૂર કરો. SSH બીજો port વાપરે તો તેનું નિયમ જાળવો. Networkમાં મંજૂરી આપવાથી guest firewallનો block દૂર થતો નથી.
Oracle Cloud Ubuntu image: નીચેનો આખો UFW block છોડો. UFW imageના આવશ્યક firewall rulesમાં દખલ કરી boot અટકાવી શકે છે. iSCSI boot/block volumes સહિતના મૂળ iptables rules જાળવો. OCI security lists અથવા NSG અને દસ્તાવેજિત guest rules વડે HTTP/HTTPS ગોઠવો. Rules flush ન કરો કે imageના firewall packages બદલો નહીં.
બીજી નવી Ubuntu image માટે UFW: પ્રદાતા UFWને સમર્થન આપે અને imageને અલગ managed firewall જરૂરી ન હોય ત્યારે જ આ commands વાપરો. Enable પહેલાં વાસ્તવિક SSH port મંજૂર કરો; અહીં port 22 માન્યો છે.
sudo apt install ufw
sudo ufw allow 22/tcp
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable
sudo ufw status verboseબંનેમાંથી યોગ્ય માર્ગ પછી નવું SSH login તપાસો. પહેલેથી ખુલ્લું session નવા જોડાણનો પુરાવો નથી. Certificate માગતાં પહેલાં આગળનો external HTTP check પણ સફળ થવો જોઈએ.
અલગ Nginx siteમાં પાનું પ્રકાશિત કરો
સર્વર પર નવી document root અને configuration બનાવો. Blockમાં hostname બદલો. Quoted EOF markers જાળવો જેથી shell $uri જેવા Nginx variables expand ન કરે.
sudo install -d -m 755 /var/www/first-site
printf '%s\n' '<!doctype html><html lang="en"><title>First deployment</title><h1>Ubuntu VPS is serving this page</h1></html>' | sudo tee /var/www/first-site/index.html
sudo tee /etc/nginx/sites-available/first-site >/dev/null <<'EOF'
server {
listen 80;
listen [::]:80;
server_name app.example.com;
root /var/www/first-site;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
EOF
sudo ln -s /etc/nginx/sites-available/first-site /etc/nginx/sites-enabled/first-site
sudo nginx -tConfiguration test સફળ થાય તો જ reload કરો:
sudo systemctl reload nginxDNS બદલતાં પહેલાં કમ્પ્યુટરથી આ hostname માટે સર્વરના IP પર request મોકલો. Default Nginx welcome pageને બદલે તમે બનાવેલું heading દેખાવું જોઈએ.
curl --resolve app.example.com:80:203.0.113.10 http://app.example.com/DNS જોડો અને HTTPS certificate મેળવો
Hostnameનો DNS A record VPSના IPv4 તરફ રાખો. IPv6 ખરેખર ચાલે ત્યારે જ AAAA ઉમેરો. જૂનો AAAA મુલાકાતીઓ અને certificate validationને ખોટા server પર મોકલી શકે છે. અહીં proxy વગર સીધો DNS VPS તરફ હોવાનું માન્યું છે.
કમ્પ્યુટરથી --resolve વગર http://app.example.com/ તપાસો. સાચું પાનું મળે પછી server પર Ubuntu archiveમાંથી Certbot અને Nginx plugin install કરો. Packages માટે Universe repository જરૂરી છે; package-not-found થાય તો પહેલાં તે સુધારો.
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d app.example.com --redirect
sudo nginx -t
sudo certbot renew --dry-run
systemctl list-timers --all certbot.timerEmail અને terms prompts અનુસરો. Certbot site configuration બદલે છે અને HTTPથી HTTPS redirect ગોઠવે છે. Renewal timer scheduled છે તે તપાસો; inactive હોય તો sudo systemctl enable --now certbot.timer ચલાવો. HTTP validation અને renewal માટે port 80 પહોંચવા યોગ્ય રાખો.
બહારથી અને reboot પછી તપાસો
કમ્પ્યુટરથી redirect, certificate અને content તપાસો. HTTPએ HTTPS તરફ જવું જોઈએ; HTTPS માન્ય certificate સાથે તમારું heading બતાવે. Curlમાં -k ઉમેરશો નહીં: તે certificate validationની ભૂલ છુપાવે છે.
curl -I http://app.example.com/
curl -I https://app.example.com/
curl -fsS https://app.example.com/હજુ test deployment હોય ત્યારે server પર sudo reboot કરો. પાછો આવે પછી deploy તરીકે જોડાઓ, systemctl is-active nginx તપાસો અને external HTTPS request ફરી કરો. Rebootથી SSH બંધ થવું સામાન્ય છે; server પાછો ન આવે તો console વાપરો.
નિષ્ફળ તપાસનું કારણ શોધો અને recovery તૈયાર રાખો
નાની સ્ક્રીન પર બધા કૉલમ જોવા કોષ્ટકને આડું સરકાવો.
| લક્ષણ | પહેલી તપાસ |
|---|---|
| SSH timeout | IP, provider/guest firewall અને recovery console |
| Permission denied (publickey) | Username, private key અને authorized_keys permissions |
| Default Nginx page | DNS destination, server_name અને enabled site |
| Certificate validation નિષ્ફળ | Public A/AAAA records અને port 80 |
| ફેરફાર પછી Nginx નિષ્ફળ | sudo nginx -t અને sudo journalctl -u nginx -n 50 --no-pager |
Login નિષ્ફળ હોય તો SSH diagnosisથી network, service અને keyની સમસ્યાઓ અલગ કરો. Site files, Nginx configuration, DNS અને rebuild steps VPSની બહાર રાખો. બીજા machine પર restore અજમાવો. Certificate private keys backupમાં હોય તો protected storage જરૂરી છે. Availability અને certificate expiry alerts ગોઠવો; એક સફળ તપાસ ભવિષ્યનું monitoring નથી.
File backup અને restore અભ્યાસ ચાલતી site બદલ્યા વિના સ્વતંત્ર copy તપાસે છે. સંપૂર્ણ recovery માટે બીજા assets, certificates અને service configuration પણ જરૂરી છે. આ deployment static files આપે છે; database અથવા application runtimeની પોતાની service અને backup પ્રક્રિયા જોઈએ. ઉમેરતી વખતે સંસાધનો માપો.
પ્રશ્નો અને જવાબો
શું હાલની વેબસાઇટ પર સીધા આ commands ચલાવી શકાય?
પહેલાં અલગ test VPS પર અજમાવો. આ ઉદાહરણ files બનાવે છે, firewall enable કરી શકે છે અને Certbotને Nginx બદલવા દે છે. હાલના serverની sites, access rules અને recovery પહેલાં તપાસો.
શું આથી WordPress, Node.js કે database install થાય છે?
ના. આ static HTTPS site બનાવે છે. તે ચાલે પછી application runtime ઉમેરો અને startup, health checks તથા data recovery તપાસો.