yii2中漂亮网址的问题

时间:2018-01-21 08:55:09

标签: php nginx yii2

我试图使用yii2和nginx设置漂亮的网址但它不起作用。我有高级模板,我在后端的配置上取消注释:

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

在nginx配置上我有这个:

server {
    listen 8080;
    server_name xxxxxxxx;

    set $base_root /var/www/xxxxxxx/html;
    root $base_root;

    #error_log /var/log/nginx/advanced.local.error.log warn;
    #access_log /var/log/nginx/advanced.local.access.log main;
    charset UTF-8;
    index index.php index.html;

    location / {
        root $base_root/frontend/web;
        try_files $uri $uri/ /frontend/web/index.php$is_args$args;

        # omit static files logging, and if they don't exist, avoid processing by Yii (uncomment if necessary)
        #location ~ ^/.+\.(css|js|ico|png|jpe?g|gif|svg|ttf|mp4|mov|swf|pdf|zip|rar)$ {
        #    log_not_found off;
        #    access_log off;
        #    try_files $uri =404;
        #}

        location ~ ^/assets/.+\.php(/|$) {
            deny all;
        }

        include /etc/nginx/mime.types;

        types {font/truetype ttf;}
        types {application/font-woff woff;}
        types {application/font-woff2 woff2;}
    }

    location ~ \.css {
       add_header Content-Type text/css;
    }

    location ~ \.js {
      add_header Content-Type application/x-javascript;
    }

    location /backend/web/assets/{
         alias /var/www/xxxxxxx/html/backend/web/assets/;

         include /etc/nginx/mime.types;

         types {font/truetype ttf;}
         types {application/font-woff woff;}
         types {application/font-woff2 woff2;}
    }

    location /frontend/web/assets/{
        alias /var/www/xxxxxxxxx/html/frontend/web/assets/;

        include /etc/nginx/mime.types;

        types {font/truetype ttf;}
        types {application/font-woff woff;}
        types {application/font-woff2 woff2;}
    }

    location /admin {
        alias $base_root/backend/web/;

        # redirect to the URL without a trailing slash (uncomment if necessary)
        #location = /admin/ {
        #    return 301 /admin;
        #}

        # prevent the directory redirect to the URL with a trailing slash
        location = /admin {
            # if your location is "/backend", try use "/backend/backend/web/index.php$is_args$args"
            # bug ticket: https://trac.nginx.org/nginx/ticket/97
            try_files $uri /backend/web/index.php$is_args$args;
        }

        # if your location is "/backend", try use "/backend/backend/web/index.php$is_args$args"
        # bug ticket: https://trac.nginx.org/nginx/ticket/97
        try_files $uri $uri/ /backend/web/index.php$is_args$args;

        # omit static files logging, and if they don't exist, avoid processing by Yii (uncomment if necessary)
        #location ~ ^/admin/.+\.(css|js|ico|png|jpe?g|gif|svg|ttf|mp4|mov|swf|pdf|zip|rar)$ {
        #    log_not_found off;
        #    access_log off;
        #    try_files $uri =404;
        #}

        location ~ \.css {
            add_header Content-Type text/css;
        }

        location ~ \.js {
            add_header Content-Type application/x-javascript;
        }

        include /etc/nginx/mime.types;

        types {font/truetype ttf;}
        types {application/font-woff woff;}
        types {application/font-woff2 woff2;}

        location ~ ^/admin/assets/.+\.php(/|$) {
            deny all;
        }
    }

    location ~ ^/.+\.php(/|$) {
        rewrite (?!^/((frontend|backend)/web|admin))^ /frontend/web$uri break;
        rewrite (?!^/backend/web)^/admin(/.+)$ /backend/web$1 break;

        fastcgi_pass 127.0.0.1:9000; # proxy requests to a TCP socket
        #fastcgi_pass unix:/var/run/php-fpm.sock; # proxy requests to a UNIX domain socket (check your www.conf file)
        fastcgi_split_path_info ^(.+\.php)(.*)$;
        include /etc/nginx/fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        try_files $fastcgi_script_name =404;
    }

    location ~ /\. {
        deny all;
    }
}

所以,当我尝试在网址上写下这一行:localhost:8080/admin/users/user/create我什么都没有得到,它显示了后端的索引页面。我做错了什么,我该如何解决?我想要结构/module/controller/action,但我不知道该怎么做。

0 个答案:

没有答案