-1

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
fgtr
  • 39
  • 2
  • 8

1 Answers1

1

Your Drupal 8 installation is redirecting homepage traffic to /fr, which then returns the nginx 404.

See the headers:

$ curl -I http://s1biose.com/
HTTP/1.1 301 Moved Permanently
Server: nginx/1.14.0 (Ubuntu)
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
Date: Wed, 27 Feb 2019 06:11:22 GMT
Location: http://s1biose.com/fr
X-Drupal-Route-Normalizer: 1
X-UA-Compatible: IE=edge
Content-language: fr
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Generator: Drupal 8 (https://www.drupal.org)
X-Drupal-Cache: HIT

You should do the following, in order:

  1. Check the server's clock. It appears to be several hours wrong.
  2. Clear Drupal's cache.
  3. Check what content your Drupal homepage is returning.
Michael Hampton
  • 244,070
  • 43
  • 506
  • 972
  • I do not understand because Drupal 8 is multi language and on Apache it works very well. I just empty the cache but it does not change anything. – fgtr Feb 27 '19 at 18:02
  • @fgtr It sounds like your current problem is with Drupal. We have a dedicated site for Drupal questions which may be able to give you more help: [drupal.se] – Michael Hampton Feb 27 '19 at 18:04
  • Thank you I will ask the question down – fgtr Feb 27 '19 at 18:07
  • I found the solution and it works ;-) but the IP address does not redirect to the domain. An idea ? https://www.nginx.com/resources/wiki/start/topics/recipes/drupal/ – fgtr Feb 27 '19 at 18:35
  • You need to add a default virtual host in nginx which redirects requests to the domain. – Tero Kilkanen Feb 27 '19 at 18:47
  • There already was a default virtual host but he (mistakenly) unlinked it, as shown in the question. – Michael Hampton Feb 27 '19 at 19:17