Yii2中的路由抛出404错误

时间:2017-06-20 11:38:29

标签: yii2

在WINDOWS / XAMPP(Apache)下的路由规则正常工作之后但是在LINUX(nginx)下它失败抛出了404-Error.What的区别在于在yii2中定义关于这两个操作系统的规则?

 'urlManager' => [
            'class' => 'yii\web\UrlManager',
            'enablePrettyUrl' => true,
            'showScriptName' => true,
            'enableStrictParsing' => true,
            'rules' => [
                '/' => 'site/login',
                'reset'=>'site/request-password-reset',
                'about' => 'site/index',
                'contact' => 'site/contact',
                'logout' => 'site/logout',
                'signup' => 'site/signup',
                'formular' => 'site/script',
                'praktikum' => 'bewerbungen/index',
                '<controller:\w+>/<id:\d+>' => '<controller>/view',
                '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
                'country' => 'country/index'
            ],
        ],
.
.
.

这是第一个Nginx-config文件,经过深思熟虑:

}
location / {
# The following 2 rules are only needed with webfinger
rewrite ^/.well-known/host-meta /public.php?service=host-meta last;
rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json last;
rewrite ^/.well-known/carddav /remote.php/carddav/ redirect;
rewrite ^/.well-known/caldav /remote.php/caldav/ redirect;
rewrite ^(/core/doc/[^\/]+/)$ $1/index.html;
try_files $uri $uri/ index.php;
}
location ~ ^(.+?\.php)(/.*)?$ {
try_files $1 = 404;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$1;
fastcgi_param PATH_INFO $2;
fastcgi_param HTTPS on;
fastcgi_pass $socket;
}
# Optional: set long EXPIRES header on static assets
location ~* ^.+\.(jpg|jpeg|gif|bmp|ico|png|css|js|swf)$ {
expires 30d;
# Optional: Don't log access to assets
access_log off;
}
}

server {
    listen 1027;
    listen [::]:1027;
     set $root_path "/srv/dev-disk-by-label-appServer/Yii2_Mail/Yii2_Mail/frontend/web";
    root $root_path;
    index yiic.php;
    set $socket "unix:/var/run/fpm-36a313b9-da05-4c39-b71e-ade398730c14.sock";
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass $socket;
    }
    access_log /var/log/nginx/8bdd6dde-225b-4ba0-ab28-5806c9046194-access.log;
    error_log  /var/log/nginx/8bdd6dde-225b-4ba0-ab28-5806c9046194-error.log;
    large_client_header_buffers 4 8k;
}

root@WSL-Server:/etc/nginx/sites-available#
这是另一个Nginx-config文件,经过深思熟虑:

root@WSL-Server:/etc/nginx/sites-available#cat default
server {
        listen 80 default_server;
        listen [::]:80 default_server;
        root /var/www/html;
        index index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {
        
                try_files $uri $uri/ =404;
        }

}

0 个答案:

没有答案