繁体   English   中英

nginx配置。 Yii项目在单独的目录中[不在root中]

[英]nginx configuration. Yii project in separate directory [not in root]

我花了超过6个小时来解决这个麻烦。

我有nginx / 1.2.7服务器和127.0.0.1:9000上的php-fpm。 我有基本的nginx配置:

server
{
    listen 80;
    server_name example.org www.example.org;

    index index.php index.html;

    access_log /srv/www/example.org/logs/access.log;
    error_log /srv/www/example.org/logs/error.log;

    location /
    {
        root /var/www/html/example.org/public_html;
        try_files $uri $uri/ /index.php;

        location ~ \.php$
        {
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param PATH_INFO $fastcgi_script_name;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            include fastcgi_params;
        }
    }

而且效果很好! 所有的php文件都可以正常工作。

但是我有一些单独的yii-project,需要在主根文件夹之外的其他目录中执行。 我在底部添加了此配置:

/srv/www/example.org/yiitest所在的位置 -它是yiitest项目的根目录(其中包含“ protected”文件夹和其他文件夹)。

location /yiitest
    {
        root /srv/www/example.org/yiitest;
        try_files $uri $uri/ /index.php?$args;

        location ~ \.php$
        {
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param PATH_INFO $fastcgi_script_name;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            include fastcgi_params;
        }
    }

但这是行不通的。 我有“找不到文件”。 我所能得到的最大信息是:example.org/yiitest/主页工作正常。 如果我转到example.org/yiitest/site/contact/,我将找不到文件。 :(

我不明白,如何在服务器的单独子目录中正确设置yii-project。

  1. 创建符号链接

     cd /var/www/html/example.org/public_html ln -s ../yiitest/public yiitest 
  2. 配置nginx

     root /var/www/html/example.org/public_html; location / { ... } location /yiitest/ { index index.php; # front end if (!-e $request_filename) { rewrite ^(.*)$ /yiitest/index.php last; break; } } location ~ \\.php$ { fastcgi_pass 127.0.0.1: 9000; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_script_name; include fastcgi_params; } 
  3. 然后配置yii框架。 您应该在配置中设置“ basePath”:

     <?php return array( 'basePath' => 'yiitest', ... ); 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM