doufu1970 2013-05-09 01:10
浏览 75
已采纳

由nginx或apache提供服务的Yii站点仅提供主页面

EDIT ONE: I've also tested this on Windows 7 with apache, and there the exact same thing happens. This means that the problem is primarily the routing of all pages to the home page.

EDIT TWO: As per a suggestion in the #yii IRC channel, I replaced the contents of the .htaccess file with a much-simplified one from a working project. This hasn't yielded any change in the problem, however.

EDIT THREE: I've got this working just fine now with some changes to my code. Answer below

I've been trying to import a site written with the Yii Framework that I've imported to my workstation. I'm encountering a problem where trying to load any page does nothing but direct to the main page. This means all requests are essentially routed exactly as if I loaded the root request. No errors pop up in the access log or error log; the requests look like the following in nginx's access log, where 'example' is either 'localhost', '127.0.0.1', or the server's IP address:

Accessing root ( http://example/ ): 
127.0.0.1 - - [08/May/2013:13:05:28 -0700] 
"GET / HTTP/1.1" 200 8436 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:20.0) Gecko/20100101 Firefox/20.0"

Accessing login ( http://example/site/login ):
127.0.0.1 - - [08/May/2013:13:07:01 -0700] 
"GET /site/login HTTP/1.1" 200 8427 "http://example/" "Mozilla/5.0 (X11; Linux x86_64; rv:20.0) Gecko/20100101 Firefox/20.0"

Accessing the same controller by http://example/index.php?r=site/login:
127.0.0.1 - - [08/May/2013:14:40:45 -0700] 
"GET /index.php?r=site/login HTTP/1.1" 200 8419 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:20.0) Gecko/20100101 Firefox/20.0"

Considering I've got 2 other Yii projects set up which work fine, which are using a server configuration similar to which I'll also paste below, I'm thinking that it may be something in the workings of the application itself that I'm not keen to yet. If anyone has any suggestions for anything else I could share, try out, or compare to in the working projects I've imported from other sites, it'd be greatly appreciated :)

edit: switched in config closer to what I had actually been using. This is probably irrelevant considering the project has the same problem while running in Apache on Windows.

server {
    server_name  localhost;
    listen 80;
    keepalive_timeout 70;

    root /usr/www/[project name omitted]/public_html;

    client_max_body_size 4M;
    client_body_buffer_size 4M;
    client_header_buffer_size 4M;

    location / {
        try_files $uri $uri/ /index.php?$args;
        autoindex on;
    }

    location ^~ /data/ {
        expires 30d;
    }


    # redirect server error pages to the static page /50x.html
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }

    #Disable logging for favicon
    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    #Disable logging for robots.txt
    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    location ~ /themes/\w+/views {
        deny all;
        access_log off;
        log_not_found off;
    }

    # Pass all .php files onto a php-fpm/php-fcgi server.
    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
        try_files $uri =404;
        #fastcgi_intercept_errors on;
        #fastcgi_connect_timeout 20;
        fastcgi_send_timeout 20;
        fastcgi_read_timeout 600; # For xdebug to work alright
        fastcgi_buffer_size 128k;
        fastcgi_buffers 4 256k;
        fastcgi_busy_buffers_size 256k;
        fastcgi_temp_file_write_size 256k;
    }
}
  • 写回答

3条回答 默认 最新

  • dongqiu8375 2013-05-13 22:40
    关注

    I've got everything sorted out after contacting the original developer of this project, who has informed me of a few changes that needed to be made. They are as follows:

    • Updating instances of code that looks like this:

      session_start();
      $_SESSION['allowdownload'] = true;
      session_write_close();
      
    • With this:

      $session=new CHttpSession;
      $session->open();
      $session['allowdownload'] = true;
      $session->close();
      
    • As well as changing the setting in protected/config/main.php for 'showScriptName' in the urlManager array to 'true' rather than 'false'. I hope that this helps someone else out at some point!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题