【问题标题】:nginx configuration. Yii project in separate directory [not in root]nginx配置。 Yii 项目在单独的目录中[不在根目录下]
【发布时间】:2013-05-28 12:49:47
【问题描述】:

我在这个问题上花了 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 项目,需要在主根文件夹以外的地方执行。 我在底部添加了这个配置:

/srv/www/example.org/yiitest — 它是 yiitest 项目的根目录(其中包含“受保护”文件夹和其他内容)。 p>

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。

【问题讨论】:

  • 我也面临着同样的问题。你找到解决办法了吗?

标签: configuration yii nginx subdirectory


【解决方案1】:
  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',
        ...
    );
    

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-26
    • 1970-01-01
    • 2016-01-17
    • 1970-01-01
    • 2012-01-26
    相关资源
    最近更新 更多