First we need to edit /etc/nginx/nginx.conf to allow virtual hosts (known as server blocks when using nginx)
This guide will show how to configure server blocks in the same manner as Ubuntu apache vhosts, using sites-available and sites-enabled.
Add the following line to the configuration in the http section:
include /etc/nginx/sites-enabled/*;
mkdir /etc/nginx/sites-available
mkdir /etc/nginx/sites-enabled
server { listen 80; server_name lukeshirnia.co.uk www.lukeshirnia.co.uk; access_log /var/log/nginx/lukeshirnia.co.uk.access.log; error_log /var/log/nginx/lukeshirnia.co.uk.error.log; root /var/www/html/lukeshirnia.co.uk; location / { index index.html index.htm index.php; try_files $uri $uri/ =404; } location ~ \.php$ { include /etc/nginx/fastcgi_params; fastcgi_pass 127.0.0.1:9000; #this means php-fpm will run on a port # fastcgi_pass unix:/run/php-fpm/example.com.sock; or you could have php-fpm running on a socket fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/html/lukeshirnia.co.uk$fastcgi_script_name; } }
Once the vhost had been created we will need to create a symbolic link from /sites-available/ to /sites-enabled/.
Moving into the /etc/nginx/sites-enabled/ directory and type the following:
ln -s /etc/nginx/sites-available/lukeshirnia.co.uk
Your vhost should now work.
If you wish to take a site offline for any reason, you can remove the symbolic link by using the 'rm' command on the vhost in /etc/nginx/sites-enabled/
And you are DONE!
Restart PHP-FPM and nginx if you face any issues.