I have an Apache server on Ubunu 18.04 with a Drupal 8 site that I want to migrate to Nginx and PHP7.3-FPM.
This is the only site on the server. I do not know Nginx at all. The site works with Apache but it does not work with Nginx.
I deleted Apache with the following command :
sudo apt autoremove --purge apache2*
Here is the configuration I had on Apache :
<VirtualHost *:80>
ServerAdmin contact@domaine.com
ServerName domaine.com
ServerAlias www.domaine.com
Protocols h2 http/1.1
DocumentRoot /var/www/www-domaine-com/web/
<Directory /var/www/www-domaine-com/web>
Options +Includes -Indexes +FollowSymLinks
AllowOverride All
Require all granted
</Directory>
<FilesMatch \.php$>
SetHandler "proxy:unix:/var/run/php/php7.3-fpm.sock|fcgi://localhost/"
</FilesMatch>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Here's how I installed Nginx :
sudo apt install nginx
sudo ufw allow in "Nginx HTTP"
I am testing the IP address of my server and the Nginx page is displayed.
sudo unlink /etc/nginx/sites-enabled/default
Here is my Nginx configuration :
sudo nano /etc/nginx/sites-available/www-domaine-com
server {
listen 80;
listen [::]:80;
server_name domaine.com www.domaine.com;
root /var/www/www-domaine-com/web;
index index.html index.php;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
include fastcgi_params;
fastcgi_pass unix:/run/php/php7.3-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
I create a symbolic link of my new configuration :
sudo ln -s /etc/nginx/sites-available/www.domaine.com /etc/nginx/sites-enabled/
I test my configuration :
sudo nginx -t
This message is displayed :
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful