1

我在nginx服务器上使用 yii2.0.3 的基本模板,并在 web/theme/demo 下有一个演示主题。

我已经为主题配置了 web.php,如下所示。

'components' => [
    'view' => [
    'theme' => [
    'pathMap' => ['@app/views' => 'theme/demo'],
    'baseUrl'   => 'theme/demo'
    ]
],

一切正常。我想从主页的 url 以及其他页面中删除web/index.php 。由于 nginx 不支持.htaccess,我在web.php文件中简单地设置了以下规则

'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'enableStrictParsing' => false,
'rules' => [],
    ],

我没有在“规则”中添加任何内容..所以干净的 url 可能无法正常工作。请帮助我从模板的每个页面中删除/web/ 。

4

2 回答 2

2

检查 Nginx 配置中的 server 块,如下所示:

server{
    listen      8082;
    server_name yii2.dev;
    access_log logs/yii2.access.log;
    error_log logs/yii2.error.log error;
    root /home/admin/web/nginx/html/basic/web/;
    location / {
            index  index.html index.php;
            if (!-e $request_filename){
                rewrite ^/(.*) /index.php?r=$1 last;
            }
    }
}
于 2015-12-27T10:17:48.987 回答
2

这是来自 nginx 网站的官方配置,专用于 Yii,所以你知道这是正确的方式(似乎是针对 Yii1,但我们可以为 Yii2 调整一些元素:

server {
        server_name domain.tld;

        root /var/www/html;
        index index.html index.php;

        # BEGIN Yii Specific location configurations

        # SEF URLs for sampleapp.
        location /{
         rewrite ^/(.*)$ /index.php?r=$1;
        }

        location ~ \.(js|css|png|jpg|jpeg?|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
                try_files $uri =404;
        }

        # END Yii Specific specific location configurations.

        # IMPORTANT: THIS SECTION MIGHT BE DIFFERENT DEPENDING ON IF
        # YOU USE PHP-FPM, PHP-FASTCGI, ETC
        location ~ \.php$ {
                root            /var/www/html;
                fastcgi_pass    127.0.0.1:9000;
                fastcgi_index   index.php;
                fastcgi_param   SCRIPT_FILENAME /usr/share/nginx/html/$fastcgi_script_name;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                include         fastcgi_params;
        }
}
于 2018-04-30T14:37:27.580 回答