How to get nginx to support Mail AutoConfigure (or any other cgi-bin scripts)

The solution is not difficult if you’re comfortable with shell/terminal commands and editing.

First, ensure you have apt-get install fcgiwrap accomplished. You NEED that module.

Next, here’s a workaround for the missing configuration info. (nothing goes automagically into the nginx vhost conf file for fcgiwrap support.)


  1. Add the following file as /etc/nginx/cgi-bin.conf
# cgi-bin.conf for virtualmin nginx
# include this in all virtual site nginx configs as needed
location /cgi-bin/ {
    gzip off;
    autoindex on;
    fastcgi_pass unix:/var/run/fcgiwrap.socket;
    fastcgi_param SCRIPT_FILENAME $document_root/../$fastcgi_script_name;
    include /etc/nginx/fastcgi_params ;
  1. Add this line to your vhost file (/etc/nginx/sites-available/’’.conf)
    include /etc/nginx/cgi-bin.conf
    (I added just before the ssl_certificate lines near the bottom.)

  2. Restart nginx (service nginx restart)


  • FWIW, it would help to rename the item in Email Settings, from Mail Client Configuration to Mail Client Auto-Configuration :slight_smile:

  • A reminder for those who want to customize the XML

    • If you want plain mailbox names (just ‘user’, not ‘user.vhost’ etc), use $mailbox
    • If you are not using the mail.hostname convention for SMTP/IMAP/POP3 host, you’ll need to manually type the correct answer in XML customization (see below)
  • A very good diagnostic help: in the vhost file (hostname.conf in /etc/nginx/sites-available) or any included file, you can add a line: add_header X-debug-message "something" always; which will be sent even if there’s a server error. I used this:
    add_header X-debug-message "droot=$document_root, file=$fastcgi_script_name" always;

  • A reminder: edit the XML at System Settings → Server Templates → (click on default) → (edit template section: Mail Client auto-configuration)… and remember to choose “XML Template below” radio button.

  • For now, XML changes to the template are not installed until you deactivate/activate client auto-config (at Email Settings → Mail Client Configuration)

Operating system Debian Linux 10
Webmin version 1.981
Usermin version 1.823
Virtualmin version 6.17-3
Authentic theme version 19.83-2

1 Like

Hey @MrPete. You rock!

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.