Skip to content

Overview

This is our developer docs about Use Nginx to Web server

Install Nginx

  1. Install Nginx
    sudo apt update
    sudo apt install nginx -y
    
  2. Adjusting the Firewall
    sudo ufw enable
    sudo ufw allow ssh
    sudo ufw allow 22  
    sudo ufw allow 'Nginx Full'
    

Setting Up Server Blocks

  1. Installing PHP and Configuring Nginx to Use the PHP Processor
    sudo apt install php-fpm php-mysql -y
    
  2. Config Site available nginx: /etc/nginx/sites-available/nginx-server
    server {
        listen 80;
        listen [::]:80;
    
        server_name nginx.example.com;
    
        root /var/www/html;
        index index.php index.html index.htm index.nginx-debian.html;
    
        location / {
            try_files $uri $uri/ =404;
        }
        location ~ \.php$ {
          include snippets/fastcgi-php.conf;
          fastcgi_pass unix:/run/php/php7.2-fpm.sock;
        }
        location ~ /\.ht {
          deny all;
        }
    }
    
  3. Enable new server block
    sudo ln -s /etc/nginx/sites-available/nginx-server /etc/nginx/sites-enabled/
    
  4. Test new config file and reload nginx
    sudo nginx -t
    sudo systemctl reload nginx