Source

iredmail / iRedMail / samples / nginx / default.conf

upstream php_workers {
    server PH_PHP_FASTCGI_SOCKET_FULL;
}

# HTTP
server {
    listen PH_HTTPD_PORT;
    server_name  _;

    root PH_HTTPD_DOCUMENTROOT;
    index index.php index.html index.htm;

    location / {
        root   PH_HTTPD_DOCUMENTROOT;
    }

    # Normal PHP scripts
    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass php_workers;
    }

    # Redirect /mail/, /iredadmin/ to https
    location ~ /mail {
        rewrite ^ https://$host$request_uri?;
    }
    location ~ /iredadmin {
        rewrite ^ https://$host$request_uri?;
    }

    # Deny all attempts to access hidden files such as .htaccess.
    location ~ /\. { deny all; access_log off; log_not_found off; }

    # Handling noisy favicon.ico messages
    location = /favicon.ico {
        return 204;     # 204 No Content
        access_log off;
        log_not_found off;
    }
}

# HTTPS
server {
    listen PH_HTTPS_PORT;
    server_name _;

    ssl on;
    ssl_certificate PH_SSL_CERT_FILE;
    ssl_certificate_key PH_SSL_KEY_FILE;

    # Roundcube webmail
    location ~ /mail(.*)\.php$ {
        include fastcgi_params;
        fastcgi_pass php_workers;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME PH_RCM_HTTPD_ROOT_SYMBOL_LINK$1.php;
    }

    location ~ /mail(.*) {
        alias PH_RCM_HTTPD_ROOT_SYMBOL_LINK$1;
        index index.php;
    }

    location ~ ^/mail/(bin|SQL|README|INSTALL|LICENSE|CHANGELOG|UPGRADING)$ { deny all; }

    # phpLDAPadmin
    location ~ /phpldapadmin(.*)\.php$ {
        include fastcgi_params;
        fastcgi_pass php_workers;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME PH_PLA_HTTPD_ROOT_SYMBOL_LINK$1.php;
    }

    location ~ /phpldapadmin(.*) {
        alias PH_PLA_HTTPD_ROOT_SYMBOL_LINK$1;
        index index.php;
    }

    # phpMyAdmin
    location ~ /phpmyadmin(.*)\.php$ {
        include fastcgi_params;
        fastcgi_pass php_workers;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME PH_PHPMYADMIN_HTTPD_ROOT_SYMBOL_LINK$1.php;
    }

    location ~ /phpmyadmin(.*) {
        alias PH_PHPMYADMIN_HTTPD_ROOT_SYMBOL_LINK$1;
        index index.php;
    }

    # phpPgAdmin
    location ~ /phppgadmin(.*)\.php$ {
        include fastcgi_params;
        fastcgi_pass php_workers;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME PH_PHPPGADMIN_HTTPD_ROOT_SYMBOL_LINK$1.php;
    }

    location ~ /phppgadmin(.*) {
        alias PH_PHPPGADMIN_HTTPD_ROOT_SYMBOL_LINK$1;
        index index.php;
    }

    # Normal PHP scripts
    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass php_workers;
    }

    # iRedAdmin: static files under /iredadmin/static
    location ~ ^/iredadmin/static/(.*)\.(png|jpg|gif|css|js) {
        alias PH_IREDADMIN_HTTPD_ROOT_SYMBOL_LINK/static/$1.$2;
    }
    # iRedAdmin: Python scripts
    location ~ ^/iredadmin(.*) {
        rewrite ^/iredadmin(/.*)$ $1 break;
        include uwsgi_params;
        uwsgi_pass unix:/var/run/uwsgi_iredadmin.socket;
        uwsgi_param UWSGI_CHDIR PH_IREDADMIN_HTTPD_ROOT_SYMBOL_LINK;
        uwsgi_param UWSGI_SCRIPT iredadmin;
        uwsgi_param SCRIPT_NAME /iredadmin;
    }
    # iRedAdmin: redirect /iredadmin to /iredadmin/
    location = /iredadmin {
        rewrite ^ /iredadmin/;
    }
}