Tüm Rehberler

Nginx Web Sunucu Kurulumu

Nginx web sunucusunu kurun ve reverse proxy olarak yapılandırın.

Orta20 dk

Kurulum Adımları

1. Nginx'i kurun:

sudo apt update
sudo apt install nginx -y

2. Nginx'i başlatın:

sudo systemctl start nginx
sudo systemctl enable nginx

3. Sunucu bloğu oluşturun:

sudo nano /etc/nginx/sites-available/siteadi

4. Yapılandırma içeriği:

server {
    listen 80;
    server_name siteadi.com www.siteadi.com;
    root /var/www/siteadi;
    index index.html;

    location / {
        try_files $uri $uri/ =404;
    }
}

5. Siteyi etkinleştirin:

sudo ln -s /etc/nginx/sites-available/siteadi /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx

6. Node.js uygulaması için reverse proxy:

location / {
    proxy_pass http://localhost:3000;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
}

7. Gzip sıkıştırmayı etkinleştirin:

gzip on;
gzip_types text/css application/javascript application/json;