Yii Framework Forum: Nginx And Yii In Subdirectory - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Nginx And Yii In Subdirectory nginx,yii,conf Rate Topic: -----

#1 User is offline   sihker 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 21-June 13

Posted 21 June 2013 - 07:34 AM

Good day.

Yii works under apache with minimal configuration needed, provided in installation documentations. Yii is in the subdirectory of /var/www/yii. Seems that php, php-fpm and nginx work, as other parts of site are working and phpinfo returns information.

Nginx conf:
user www-data;
worker_processes 4;
pid /run/nginx.pid;

events {
        worker_connections 768;
}
http {
        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        include /etc/nginx/mime.types;
        default_type application/octet-stream;
        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;
        gzip on;
        gzip_disable "msie6";
        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
}


Virtual server conf:
server {
    listen 8080;
    server_name daisy.fuentes;
    client_max_body_size 50m;
    set $yii_bootstrap "index.php";
    root /var/www/yii;

    location / {
      include /etc/nginx/fastcgi_params;
      fastcgi_param SCRIPT_NAME '';
      fastcgi_param PATH_INFO $fastcgi_script_name;
      fastcgi_pass unix:/var/www/daisy.fuentes/fuentes.socket;
    }

    location /static {
      root /var/www/daisy.fuentes/root;
      expires 30d;
    }

    location ~ /\.ht {
      deny all;
    }

    location ~ /yii/(protected|framework|nbproject) {
      deny all;
      access_log off;
      log_not_found off;
    }

    location ~ /yii/themes/\w+/views {
      deny all;
      access_log off;
      log_not_found off;
    }

    location /yii/ {
      index  $yii_bootstrap;
      try_files $uri /$uri/ /yii/$yii_bootstrap?$args;
    }

    location ~ /yii/.*\.php$ {
      fastcgi_split_path_info  ^(.+\.php)(.*)$;
      
      fastcgi_pass   127.0.0.1:19000;
      include fastcgi_params;
      
      set $fsn /$yii_bootstrap;
      fastcgi_param  SCRIPT_FILENAME  $document_root$fsn;
      
      #PATH_INFO and PATH_TRANSLATED can be omitted, but RFC 3875 specifies them for CGI
      fastcgi_param  PATH_INFO        $fastcgi_path_info;
      fastcgi_param  PATH_TRANSLATED  $document_root$fsn;
    }
}


Perl catalyst is working OK, yii is not so lucky, I'm getting a lot of 404's, no styles and seems, that no javascript
Typical example being
[21/Jun/2013:10:54:42 +0000] "GET /yii/css/common.css HTTP/1.1" 404 1572 "XXX/yii/index.php/site/login" "Mozilla/5.0 (X11; Linux x86_64; rv:21.0) Gecko/20100101 Firefox/21.0"

Although the files are there, in this case the /yii/css/common.css, but my guess is, nginx rewrite somehow mangles the uri.
Any insights on how to get yii up and running in this configuration?

Greetings.
0

#2 User is offline   sihker 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 21-June 13

Posted 28 June 2013 - 08:47 AM

Ok, apache somehow works even if the files are owned by the root. Seems, that nginx is not working that way. Had to chown -R www-data:www-data yii directory.
Also ended up with this virtual server conf that works:

server {
    listen 80;
    server_name ur.mom;
    client_max_body_size 50m;

    root /var/www;

    charset utf-8;

    set $yii_bootstrap "index.php";

    location / {
      include /etc/nginx/fastcgi_params;
      fastcgi_param SCRIPT_NAME '';
      fastcgi_param PATH_INFO $fastcgi_script_name;
      fastcgi_pass unix:/var/www/catalyst/catalyst.socket;
    }

    location /static {
      root /var/www/catalyst/root;
      expires 30d;
    }

    location /yii {
        index $yii_bootstrap;
        try_files $uri $uri/ /yii/$yii_bootstrap?$args;
    }

    location ~ /yii/.*\.php$ {
      fastcgi_split_path_info  ^(.+\.php)(.*)$;

      set $fsn /$yii_bootstrap;
      if (-f $document_root$fastcgi_script_name){
          set $fsn $fastcgi_script_name;
      }

      #fastcgi_pass   127.0.0.1:19000;
      fastcgi_pass unix:/var/www/yii/yii.socket;
      include fastcgi_params;
      
      fastcgi_param  SCRIPT_FILENAME  $document_root$fsn;
      fastcgi_param  PATH_INFO        $fastcgi_path_info;
      fastcgi_param  PATH_TRANSLATED  $document_root$fsn;
    }
}


Took me only two weeks and a lot of googling. Thank you for a lively discussion and support :D
0

#3 User is offline   xarope 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 26-September 13

Posted 26 September 2013 - 02:11 AM

I have a similar configuration when I was doing testing, perhaps you can also try this config, which embeds the second *.php location inside the /yii location:

    location /yii {
        index $yii_bootstrap;
        try_files $uri $uri/ /yii/$yii_bootstrap?$args;

      location ~ \.php$ {
        fastcgi_split_path_info  ^(.+\.php)(.*)$;

        set $fsn /$yii_bootstrap;
        if (-f $document_root$fastcgi_script_name){
            set $fsn $fastcgi_script_name;
        }

        #fastcgi_pass   127.0.0.1:19000;
        fastcgi_pass unix:/var/www/yii/yii.socket;
        include fastcgi_params;
      
        fastcgi_param  SCRIPT_FILENAME  $document_root$fsn;
        fastcgi_param  PATH_INFO        $fastcgi_path_info;
        fastcgi_param  PATH_TRANSLATED  $document_root$fsn;
      }
  }


NB: for mine, as I'm on ubuntu, I use 127.0.0.1:9000 rather than socket configuration for php5-fpm
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users