Советы по настройке Nginx + FastCGI для Webasyst

Содержание...

Для работы фреймворка в среде Nginx + FastCGI без использования Apache необходимо включить в конфигурационный файл Nginx ряд специальных настроек.

Ниже приведен пример конфигурации для следующих условий:

server {
    listen 80;

    server_name fw;
  
    root /var/www/fw;
    index index.php;

    try_files $uri $uri/ /index.php?$query_string;

    location /index.php {
        include /etc/nginx/fastcgi_params;
        fastcgi_pass  127.0.0.1:9000;
    }
    
    # for install only
    location /install.php {
        include /etc/nginx/fastcgi_params;
        fastcgi_pass  127.0.0.1:9000;
    }    
    
    location /api.php {
        fastcgi_split_path_info  ^(.+\.php)(.*)$;
        include /etc/nginx/fastcgi_params;
        fastcgi_pass  127.0.0.1:9000;
    }    

    location ^~ /wa-data/protected/ {
        #return 403;
        #X-Accel-Redirect
        internal;
    }

    location ~* ^/wa-(log|config|cache|system)/ {
        return 403;
    }

    location ~* ^/wa-data/public/contacts/photos/[0-9]+/ {
         root /var/www/fw/;
         access_log off;
         expires  30d;
         error_page   404  =  @contacts_thumb;
    }

    location @contacts_thumb {
        include /etc/nginx/fastcgi_params;
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_param  SCRIPT_NAME  /wa-data/public/contacts/photos/thumb.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root/wa-data/public/contacts/photos/thumb.php;
    }
  
    # photos app
    location ~* ^/wa-data/public/photos/[0-9]+/ {
        access_log   off;
        expires      30d;
        error_page   404  =  @photos_thumb;
    }

    location @photos_thumb {
        include /etc/nginx/fastcgi_params;
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_param  SCRIPT_NAME  /wa-data/public/photos/thumb.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root/wa-data/public/photos/thumb.php;
    }
    # end photos app
    
    # shop app
    location ~* ^/wa-data/public/shop/products/[0-9]+/ {
        access_log   off;
        expires      30d;
        error_page   404  =  @shop_thumb;
    }
    location @shop_thumb {
        include /etc/nginx/fastcgi_params;
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_param  SCRIPT_NAME  /wa-data/public/shop/products/thumb.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root/wa-data/public/shop/products/thumb.php;
    }
    # end shop app
    
    # mailer app
    location ~* ^/wa-data/public/mailer/files/[0-9]+/ {
        access_log   off;
        error_page   404  =  @mailer_file;
    }
    location @mailer_file {
        include /etc/nginx/fastcgi_params;
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_param  SCRIPT_NAME  /wa-data/public/mailer/files/file.php;
        fastcgi_param  SCRIPT_FILENAME $document_root/wa-data/public/mailer/files/file.php;
    }
    # end mailer app

    location ~* ^.+\.(jpg|jpeg|gif|png|js|css)$ {
        access_log   off;
        expires      30d;
    }
}