Recently trying to build the company's website with Nginx+symfony, because Nginx does not support PathInfo mode, you must modify Nginx (I am using nginx1.5.1) Profile/etc/nginx/config.d/ Default.conf so that it logically supports the mapping of the URL logical path to the physical path, the following is the contents of my default.conf file:
server {
listen ;
server_name localhost;
Location/{
root /usr/share/nginx/html/symfony/web;
Index index.html index.htm index.php;
}
Location ~ ^ (. +\.php) (. *) $ {
root /usr/share/nginx/html/symfony/web; Fastcgi_index index.php; fastcgi_split_path_info ^ (. +\.php) (. *) $;
Fastcgi_param script_filename $document _root$fastcgi_script_name; Fastcgi_param path_info $fastcgi _path_info; Fastcgi_param path_translated $document _root$fastcgi_path_info; Fastcgi_pass 127.0.0.1:9000; Include Fastcgi_params;
}
}
After you implement a logical map of the URL, you can see the actual effect in the Web page (note the circled part of the diagram):
However, if in prod mode (that is, access to the path under 192.168.10.133/app.php/) prompts for an error "No route for Get/", which is not a problem with our pathinfo configuration (starting from this aspect, the cost is too old), But because Symfony2 does not provide us with the content of the PROD mode, we need to modify the Symfony/app/routing.yml file to provide him with a logical path map, as follows a configuration item that I copied from the Routing_dev.xml file:
More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Servers/web/
1 # Acmedemobundle routes (to be removed)
2 _acme_demo:
3 resource: "@AcmeDemoBundle/resources/config/routing.yml"
This allows the symfony to get the Src/acme/demobundle/resources/config/routing.yml file (as shown below) in prod mode, using URL logic mapping. With this file you can find the @acmedemobundle/controller/democontroller.php file to show the effect shown above
1 _demo:
2 resource: "@AcmeDemoBundle/controller/democontroller.php"
3 type:annotation
4 prefix:/demo
However, when the actual access to the Http://192.168.10.133/app.php/demo/hello/bean did not show the desired effect, a mistake was reported:
Cannot import resource "/usr/share/nginx/html/symfony/src/acme/demobundle/resources/config/config.yml" from "/usr/ Share/nginx/html/symfony/app/config/config.yml ".
Online Search, StackOverflow on the most of the answers to let you in the resource field to indent four characters, and so on my question does not apply, Later found in the above error message there is a line of words said to be registered in the appkernel.php Acmedemobundle and so on, so find/usr/share/nginx/html/symfony/app/ appkernel.php, found the following sentence:
if (In_array ($this->getenvironment (), Array (' Dev ', ' test ')) {
2 $bundles [] = new Acme\demobundle\acmedemobundle ();
3 $bundles [] = new Symfony\bundle\webprofilerbundle\webprofilerbundle ();
4 $bundles [] = new Sensio\bundle\distributionbundle\sensiodistributionbundle ();
6 $bundles [] = new Sensio\bundle\generatorbundle\sensiogeneratorbundle ();
7 }
So far, all we need to do is modify array (' dev ', ' test ') for array (' Dev ', ' Test ', ' prod ') so that Symfony will register Acmedemobundle in prod mode, The results of the experiment were shown as follows:
Source: http://www.cnblogs.com/beanmoon/p/3181733.html