Let's migrate Apache2 to Nginx to increase WordPress website performance.
1. Install Nginx
sudo apt update
sudo apt upgrade
sudo apt install nginx
2. Allow Nginx from Firewall
sudo ufw allow "Nginx Full"
3. Configure Nginx with 8080 Port
Open file with editor
sudo vi /etc/nginx/sites-available/default
Change port to 8080
listen 8080 default_server;
listen [::]:8080 default_server;
Test configuration before apply
sudo nginx -t
Start Nginx server
sudo service nginx start
Test connection
curl http://localhost:8080
4. Configure website config file
Create a new config file
sudo touch /etc/nginx/sites-available/zemna.net.conf
Open config file using editor
sudo vi /etc/nginx/sites-available/zemna.net.conf
Update configuration
server {
listen 80;
listen [::]:80;
root /var/www/zemnanet-website/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name zemna.net www.zemna.net;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
}
Activate configuration
sudo ln -s /etc/nginx/sites-available/zemna.net.conf /etc/nginx/sites-enabled/
5. Stop Apache2 and Start Nginx
sudo service apache2 stop
sudo srvice nginx start
6. Install Lets Encrypt SSL
Install required package
sudo apt install python-certbot-nginx -t stretch-backports
Obtaining an SSL Certificate
sudo certbot --nginx -d zemna.net -d www.zemna.net
7. Remove Apache2
sudo apt remove apache2
sudo apt autoremove
Remove from firewall configuration
sudo ufw delete allow "WWW Full"