Skip to content
This repository has been archived by the owner on Jan 10, 2019. It is now read-only.

Nginx参考配置(含rewrite)

Che Kun edited this page Aug 4, 2013 · 3 revisions
server {
    listen 80;
    root /path/to/dilicms/;
    index index.php;
    server_name love.dilicms.com;

    location ~ ^(/(application|system|services|shared|admin/backup|admin/config|admin/controllers|admin/core|amdin/errors|admin/hooks|admin/language))/ {
        deny all;
    }

    location / {

        if ($request_uri ~* index/?$)
        {
            rewrite ^/(.*)/index/?$ /$1 permanent;
        }

        if (!-d $request_filename)
        {
            rewrite ^/(.+)/$ /$1 permanent;
        }

        set $admin '';

        if ($request_uri ~* ^/admin/) {
            set $admin A;
        }

        if ($request_uri ~* ^/install/) {
            set $admin B;
        }

        if (!-e $request_filename) {
            set $admin "X${admin}";
        }

        if ($admin = XA) {
            rewrite ^/admin/(.*)$ /admin/index.php?/$1 last;
            break;
        }

        if ($admin = XB) {
            rewrite ^/install/public/(.*)$ /install/public/index.php?/$1 last;
        }

        if ($admin = X) {
            rewrite ^/(.*)$ /index.php?/$1 last;
            break;
        }

    }


    location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /path/to/dilicms$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }
}

Clone this wiki locally