How to configure Symfony2 in Nginx

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.