← Back to VPS & Dedicated

Setting Up Nginx on Your VPS

Nginx is a high-performance web server ideal for serving static content and as a reverse proxy for PHP-FPM. It uses less memory than Apache and handles high concurrency well.

Installing Nginx

apt update\napt install nginx -y\nsystemctl enable nginx\nsystemctl start nginx

Visit your VPS IP in a browser to see the Nginx welcome page.

Configuring a Server Block (Virtual Host)

Create a config file for your domain:

nano /etc/nginx/sites-available/yourdomain.com

Add:

server {\n  listen 80;\n  server_name yourdomain.com www.yourdomain.com;\n  root /var/www/yourdomain.com/public;\n  index index.php index.html;\n\n  location / {\n    try_files $uri $uri/ /index.php?$args;\n  }\n\n  location ~ \.php$ {\n    include snippets/fastcgi-php.conf;\n    fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;\n  }\n}

Enabling the Site

ln -s /etc/nginx/sites-available/yourdomain.com /etc/nginx/sites-enabled/\nnginx -t\nsystemctl reload nginx

Was this article helpful?

On This Page