1. First enable Nginx pathinfo
If AMH is installed on your host, congratulations, and configuration is easy. First install the "AMPathinfo" module, and then enable the pathinfo of your website on the list of modules.
If AMH is not installed on your host, you don't have to worry about it. To enable pathinfo, you actually add two lines of configuration code.
Fastcgi_split_path_info ^ (. + \. php) (. *) $;
Fastcgi_param PATH_INFO $ fastcgi_path_info;
I don't know how to add it? Don't worry, I will tell you below
2. Main configuration file
Each nginx site has a master configuration file, which is placed under/alidata/server/nginx/conf/vhosts (your path may be different from mine, run the "nginx-t" command to view the configuration file.
Server {
Listen 80;
Server_name www.111cn.net; # host domain name, do not say you do not know
Index index.html index.htm index. php app. php; # default main file, I added app. php
Set $ subdomain '';
Root/alidata/www/sample/web; # physical path of the website code disk. Note that the root directory of symfony is web
Include rewrite/symfony2.conf; # rewrite end # introduce symfony-related configuration.
Location ~ \. Php (/.*)? $
{
# Fastcgi_pass unix:/tmp/php-cgi.sock;
Fastcgi_pass 127.0.0.1: 9000;
Fastcgi_index index. php;
Fastcgi_split_path_info ^ (. + \. php) (. *) $; # key configuration of pathinfo
Fastcgi_param PATH_INFO $ fastcgi_path_info; # key configuration of pathinfo
Include fastcgi. conf;
}
Location ~ . * \. (Gif | jpg | jpeg | png | bmp | swf) $
{
Expires 30d;
}
Location ~ . * \. (Js | css )? $ # File cache time of js and css
{
Expires 1 h;
}
Access_log/alidata/log/nginx/access/sample. log; # Error log
}
~
3. Symfony-related configuration
I found out this by myself. nginx configuration instructions are also available on the official symfony website. I tried it and failed to understand it. Do you still remember that the previous configuration section contains include rewrite/symfony2.conf? Now I will paste this configuration file.
Location /{
Index app. php;
Try_files $ uri @ rewriteapp;
}
Location @ rewriteapp {
Rewrite ^ (. *) $/app. php/$1 last;
}
You can see that there are not a lot of code, but the actual configuration of symfony is like this. Remember to put this configuration file in the rewrite folder