I have an app that previously run on apache without any problem, now i want to change it to nginx. So i transfer the app to nginx server to test first.
First problem i encounter, i could not login (click on the login button it just stay there), i google and solved that issue.
but now after login im getting this error
CHttpException
The system is unable to find the requested action "error". (/usr/share/nginx/www/xxx/framework/web/CController.php:483)
#0 /usr/share/nginx/www/xxx/framework/web/CController.php(270): CController->missingAction('error')
#1 /usr/share/nginx/www/xxx/framework/web/CWebApplication.php(282): CController->run('error')
#2 /usr/share/nginx/www/xxx/framework/base/CErrorHandler.php(331): CWebApplication->runController('site/error')
#3 /usr/share/nginx/www/xxx/framework/base/CErrorHandler.php(204): CErrorHandler->render('error', Array)
#4 /usr/share/nginx/www/xxx/framework/base/CErrorHandler.php(129): CErrorHandler->handleException(Object(CHttpException))
#5 /usr/share/nginx/www/xxx/framework/base/CApplication.php(720): CErrorHandler->handle(Object(CExceptionEvent))
#6 [internal function]: CApplication->handleException(Object(CHttpException))
#7 {main}
First make sure nginx runs fine with a simple .html page; if not, check your installation.
Next check if nginx can run a simple .php script page such as <? phpinfo(); ?>; if not, check your php-fpm installation because nginx – as opposed to Apache – doesn’t include PHP support out of the box. I’d also change the php-fpm user from apache to nginx at /etc/php-fpm.d/www.conf.
Make sure you can display the Yii requirements page at (yii folder)/requirements and fix any missing requirements.
From your post it looks like that all of the above are working because you’re getting a Yii CHttpException (and not a PHP) error, but it never hurts to double check. It seems to me that the application is failing because of the UrlManager rules in protected/config/main.php are not appropriate for an nginx environment (especially if they depended upon Apache .htaccess rules) but to rule out nginx then check the next steps.
I use CentOS so YMMV with a different Linux flavor.
nginx will look for configuration files in /etc/nginx/conf.d that have a .conf extension and load them (that’s how it can manage more than 1 app). One of my configurations is called xyz.conf (details obfuscated) and looks as follows:
server {
listen 1.2.3.4:80;
set $host_path "/home/xyz";
server_name xyz.com *.xyz.com;
root $host_path;
set $yii_bootstrap "index.php";
charset utf-8;
location / {
index index.html $yii_bootstrap;
try_files $uri $uri/ /$yii_bootstrap?$args;
}
#avoid processing of calls to unexisting static files by yii
location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
try_files $uri =404;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php {
fastcgi_split_path_info ^(.+\.php)(.*)$;
#let yii catch the calls to unexising PHP files
set $fsn /$yii_bootstrap;
if (-f $document_root$fastcgi_script_name){
set $fsn $fastcgi_script_name;
}
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fsn;
#PATH_INFO and PATH_TRANSLATED can be omitted, but RFC 3875 specifies them for CGI
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fsn;
}
}
fastcgi_params (in /etc/nginx) contains the default parameters that come with php-fpm so no changes there are needed.
If indeed the problem is in the UrlManager rules, I’m afraid you’ll need a programmer to help you. Perhaps if you post the urlManager section of protected/config/main.php you can get help here.
The rules look fine except that I’d be concerned about the routes being written in PascalCase (words created by concatenating capitalized words) if your system is Linux because unlike Windows, it makes a difference.
One possible scenario is that Yii can’t find the route as spelled so it automatically goes to the errorAction() method in SiteController (which it calls “site”, not “Site”) to display an error page. However, it doesn’t find it and thus generates the CHttpException, as shown in the error message you posted originally. Look in protected/controllers/SiteController for the actionError() method; if it’s not there (or written in PascalCase) that’s probably the cause of the error.
If the problem is indeed the PascalCase spelling, rather than renaming everything (files and folders) to camelCase (same thing but the first word is in lowercase) you can rewrite the urlManager rules to make them case insensitive (see the Class Reference):
nginx handles mod_rewrites internally, as the scripts I posted show (the location directives), so there’s no specific module you need to enable/disable for URL rewrites. I understand you’re not a programmer but if you’re going to be fiddling with this you might as well learn about nginx at nginx.org. Good luck.
but if i go to http://mysite.com/MyApp it will throw a CHttpException error and the app is not working.
the app is locate in /usr/share/nginx/www/MyApp
i try to change $host_path/MyApp; to $host_path; though it would work but it doesn’t, the login page of my app show up but when try to login it doesn’t do anything.