How to migrate my Apache server to Nginx?

fgtr asked:

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.

I deleted Apache with the following command :

sudo apt autoremove --purge apache2*

Here is the configuration I had on Apache :

<VirtualHost *:80>
   ServerAdmin [email protected]
   Protocols h2 http/1.1
   DocumentRoot /var/www/www-s1biose-com/web/

   <Directory /var/www/www-s1biose-com/web>
      Options +Includes -Indexes +FollowSymLinks
      AllowOverride All
      Require all granted

   <FilesMatch \.php$>
      SetHandler "proxy:unix:/var/run/php/php7.3-fpm.sock|fcgi://localhost/"

   ErrorLog ${APACHE_LOG_DIR}/error.log
   CustomLog ${APACHE_LOG_DIR}/access.log combined

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 :

server {
    listen :80;
    listen [::]:80;

    root   /var/www/www-s1biose-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/ /etc/nginx/sites-enabled/

I test my configuration :

sudo nginx -t

This message is displayed :

nginx: [emerg] no host in ":80" of the "listen" directive in /etc/nginx/sites-enabled/www-s1biose-com:2
nginx: configuration file /etc/nginx/nginx.conf test failed

If I enter the url of my site, I have the following message :

enter image description here

sudo ss -tnlp

State     Recv-Q     Send-Q               Local Address:Port          Peer Address:Port                                                     
LISTEN    0          80                  *         users:(("mysqld",pid=5833,fd=20))              
LISTEN    0          128               *         users:(("systemd-resolve",pid=702,fd=13))      
LISTEN    0          128                     *         users:(("sshd",pid=903,fd=3))                  
LISTEN    0          100                     *         users:(("master",pid=1432,fd=13))              
LISTEN    0          128              *         users:(("monit",pid=897,fd=6))                 
LISTEN    0          50              [::ffff:]:7983                     *:*         users:(("java",pid=1062,fd=48))                
LISTEN    0          128                              *:8080                     *:*         users:(("node /var/www/w",pid=4281,fd=11))     
LISTEN    0          128                           [::]:22                    [::]:*         users:(("sshd",pid=903,fd=4))                  
LISTEN    0          50                               *:8983                     *:*         users:(("java",pid=1062,fd=125))               
LISTEN    0          100                           [::]:25                    [::]:*         users:(("master",pid=1432,fd=14))

My answer:

The error message shows you have an error in the specified line of your nginx configuration.

    listen :80;

This is a typo; it should appear as:

    listen 80;

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.