1

I am using basic template of yii2.0.3 on a nginx server and have a demo theme under web/theme/demo.

I have config the web.php as below for the theme.

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

Everything is working fine.I want to remove the web/index.php from the url of the home page as well as from other pages too. As nginx does not support .htaccess i have put simple the below rules on the web.php file

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

I have not put anything inside 'rules'..so clean url may not working properly. Please help me to remove /web/ from each page of the template.

user3172663
  • 312
  • 3
  • 14
  • From the guide: http://www.yiiframework.com/doc-2.0/guide-start-installation.html#recommended-nginx-configuration – chris--- Apr 24 '15 at 12:31

2 Answers2

2

Check the server block in Nginx configuration as following:

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;
            }
    }
}
Jay
  • 41
  • 3
2

Here's the official config from the nginx website, dedicated for Yii, so you know it's the right way (It seems to be for Yii1, but we can adjust some elements for 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;
        }
}
NaturalBornCamper
  • 3,675
  • 5
  • 39
  • 58