dongzou3751 2016-04-28 17:45
浏览 135

Yii2 url重写后缀(php)问题

I Have some url pattern that should work on my website.

[
'pattern'=>'page/result',
'route'=>'site/index',
'suffix'=>'.html'
],
[
'pattern'=>'page/result',
'route'=>'site/index',
'suffix'=>'.php'
],

In these two url suffix .html is working fine but .php suffix is not working in MY Nginx Server. Also check the my site nginx setting.

server {


listen 8081 default_server;
    listen [::]:8081 default_server;

    root /var/www/html/yii2project/frontend/web;

    # Add index.php to the list if you are using PHP
    index index.html index.htm index.nginx-debian.html index.php;


    access_log  /var/log/yii2/access.log;
    error_log   /var/log/yii2/error.log;

    server_name yii2.local;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        #try_files $uri $uri/ =404;
           root   /var/www/html/yii2/frontend/web;
           index  index.html index.htm index.php;
           try_files $uri $uri/ /index.php?$args;#now
           #rewrite ^/(.*)$ /$1 last;
           #if ($http_host ~* "^yii2.local:8081"){
           #rewrite ^(.*)$ http://www.yii2.local:8081$1 redirect;
            #}

       }

        #caching of static files
        location ~*  \.(jpg|jpeg|png|gif|ico|css|js)$ {
           expires 365d;
        }


    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
    #   include snippets/fastcgi-php.conf;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
    #
    #   # With php5-cgi alone:
    #   fastcgi_pass 127.0.0.1:9000;
    #   # With php5-fpm:
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include /etc/nginx/fastcgi_params;
                fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;               # include fastcgi.conf;
                include fastcgi.conf;#now 
        fastcgi_read_timeout 300;    

    } 
}

http://yii2.local:8081/page/result.html (working) http://yii2.local:8081/page/result.php (not working)

Please see the nginx setting and tell me where i'm wrong configurartion.

  • 写回答

1条回答 默认 最新

  • douzhangli9563 2016-04-28 21:08
    关注

    You have three different document roots which seems a little strange:

    /var/www/html/yii2project/frontend/web
    /var/www/html/yii2/frontend/web
    /usr/share/nginx/html
    

    The first will be used to locate resource files (.css and .js). The second will be used to locate .html files. The third will be used to locate .php files.

    Assuming that all of your files share a common root, it is usual to place a root directive in the server block and allow all location blocks to inherit the value.

    You should probably change the value of your first root directive. Delete the root directive in the location / block, and change the definition of SCRIPT_FILENAME.

    server {
        ...
        root /var/www/html/yii2/frontend/web;
        ...
        location / { ... }
        location ~*  \.(jpg|jpeg|png|gif|ico|css|js)$ { ... }
        location ~ \.php$ {
            ...
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥50 易语言把MYSQL数据库中的数据添加至组合框
  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况