Webmail_Configure NGINX - SomethingWithHorizons/mailserver GitHub Wiki

Configure Nginx for Rainloop usage.

Nginx requires specific settings to match Rainloop's way of working.

Procedure

Have Nginx not refer to the default "It works" directory / page. Provide Nginx with a configuration file to: have it listen on port 80 for all addresses, set the root for the hosted files looking for index or index.php files, make it look in specific places and return a 404 message if unsuccessful, and have PHP deal with the .php scripts found.

  1. Disable the Nginx default vhost:

    unlink /etc/nginx/sites-enabled/default
  2. Create the Nginx configuration file to create a vhost that listens to all http request on port 80:

    # Redirect the following block until End Of File (EOF) via `cat` to a webmail file
    cat << 'EOF' > /etc/nginx/sites-enabled/webmail
    
    # Settings for the first (and only) server
    server {
      
      # Make the default Nginx vhost listen on port 80
      listen 80 default_server;
    
      # Define the path to look for files
      root /var/www/rainloop;
      # Define the default files to look for (when no file is referenced request URL)
      index index.php;
    
      # Instruct Nginx to recursively look (starting from the root defined above), for 1:files 2:directories (referenced in the request URL) and 3) return a 404 otherwise.
      location / {
        try_files $uri $uri/ =404;
      }
    
      # Process all files with a `.php` extension
      location ~ \.php$ {
        
        # Split the input into two groups, filename and its arguments (title.php?page=landing -> title.php / ?page=landing)
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
    
        # Define the socket file that is used as the php-fpm  "interface" to send stuff to
        fastcgi_pass   unix:/var/run/php/php7.0-fpm.sock;
    
        # Send the fastcgi params (basically a set of default PHP "environment" variables)
        include        fastcgi_params;
    
        # Add a specific parameter appending the already included list
        fastcgi_param  SCRIPT_FILENAME $request_filename;
      }
    }
    EOF
  3. Restart Nginx service to effectuate the changes:

    service nginx restart
⚠️ **GitHub.com Fallback** ⚠️