Channel created
sudo apt update


Install Nginx

sudo apt install nginx -y

sudo ufw allow 'Nginx Full'


Nginx Status

sudo systemctl status nginx


Enable Nginx

sudo systemctl enable nginx



Website Host Configuration path

/etc/nginx/sites-available/


and then enable the website

/etc/nginx/sites-enabled/
For Make Change In Nginx

sudo systemctl restart nginx

sudo systemctl reload nginx
Static Website Configuration

server {
listen 80;
listen [::]:80;
server_name example.com;

root /var/www/html;
index index.html index.htm;

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

# Security headers
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-XSS-Protection "1; mode=block" always;
add_header X-Content-Type-Options "nosniff" always;

# Gzip compression
gzip on;
gzip_vary on;
gzip_min_length 1024;
gzip_types text/plain text/css text/xml text/javascript application/javascript application/xml+rss application/json;

# Deny access to hidden files
location ~ /\. {
deny all;
}
}
For PHP Web Configuration

server {
server_name example.com;
root /var/www/html;

index index.php index.html index.htm;

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

location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

location ~ /\.ht {
deny all;
}

listen 80;
}
Reverse Proxy Configuration

server {
listen 80;
server_name example.com;
return 301 https://$host$request_uri;
}

server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name example.com;

# Security Headers
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-XSS-Protection "1; mode=block" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;

# Proxy settings
location / {
proxy_pass http://localhost:8000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
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;

# Timeout settings
proxy_read_timeout 300s;
proxy_connect_timeout 300s;
proxy_send_timeout 300s;
}

# Gzip compression
gzip on;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
gzip_proxied any;
gzip_min_length 256;
}
Configuration Test

sudo nginx -t
Config Enable

sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
SSL Install for Domain :

sudo apt install certbot python3-certbot-nginx -y


Active SSL :

sudo certbot --nginx -d example.com