User Tools

Site Tools


virtual-block

Add a custom server block to Nginx

All your server blocks should be saved in the folder /etc/nginx/conf.d if you have been following with this wiki. All commented parts are where you add your domain/path to disk.

Firsty open up a blank file

sudo nano /etc/nginx/conf.d/example.conf
  • Where 'example.conf ' is, add your domain name eg guildfordwebservices.conf
  • Add this to the blank file
server {
  listen 80;
  listen [::]:80;
  server_name example.com; #CHANGE THIS TO YOUR DOMAIN/SUB DOMAIN
  root /add/path/where/your/webdata/is/; #CHANGE THIS TO WHERE YOUR WEB FILES ARE
  index index.php index.html index.htm index.nginx-debian.html;
 
  location / {
    try_files $uri $uri/ /index.php;
  }
 
  location ~ \.php$ {
    fastcgi_pass unix:/run/php/php7.4-fpm.sock;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    include snippets/fastcgi-php.conf;
  }
 
 # A long browser cache lifetime can speed up repeat visits to your page
  location ~* \.(jpg|jpeg|gif|png|webp|svg|woff|woff2|ttf|css|js|ico|xml)$ {
       access_log        off;
       log_not_found     off;
       expires           360d;
  }
 
  # disable access to hidden files
  location ~ /\.ht {
      access_log off;
      log_not_found off;
      deny all;
  }
}

Run Nginx -t to check for no errors, then reload Nginx 'sudo systemctl restart nginx'

If that is successfull, run Certbot to secrue the site running 'sudo certbot –nginx'

virtual-block.txt · Last modified: 2023/05/17 22:52 by 127.0.0.1