Configuring the Thinkphp Project on Nginx, nginxthinkphp project _php Tutorial

Source: Internet
Author: User

Configuring the Thinkphp Project on Nginx, nginxthinkphp project


The previous time with the Apache with TP developed a small website, also is I use TP the first combat. I am accustomed to use PathInfo mode, the local run everything is normal, but deployed to the server, because the other side is using Nginx, the default is not support thinkphp PathInfo mode, so lead to path error, there is a page loop jump problem, So I downloaded Nginx to the local test.

In fact, to solve the problem of Nginx does not support pathinfo, there are two solutions, one is not to use PathInfo mode, the second is to modify Nginx configuration file, so that it supports pathinfo. In order to simplify the problem, I chose the first way, because on the second way, I looked at a lot of information, found that everyone's methods are not the same, some are very different, easy to cause misleading, so I choose to start from the simple, choose the normal mode, although there is a certain risk. When the index.php corresponding to the foreground code modified, found that the front desk is basically normal, but the background still has the problem of redirection. Toss for a long time, I just thought to look at the log file, the original editor is the problem, it seems that the log file is really important, has not been attached to the past. The output appears on the first line of the config.php file,

1. At the time of logging in, I was through the external JS file to send Ajax request verification, JS and thinkphp module function communication encountered some problems, has not known the correct path to write, also did not find relevant information, only a variety of tests, fortunately found a solution, By directly bringing the entry file name, the code is as follows

  1   var url= "System.php?m=login&a=dolog";   2  $.post (url,{"staffname":  $staffname , "staffpwd":  $staffpwd , "Verifycode":  $verifycode },  function   (data) {  3   if  (data== " Codeerr ") {  4  alert (" The CAPTCHA is wrong! ");   5 }  else   if  (data== "Authempty" ) {  6  alert ("Please Lose Enter your username or password!           ")   7 }  else   if  (data==" Autherr ") {  8  Alert ("The user name or password is wrong!") ");   9 }  else   if  (data== "Success" ) {  ten  alert ("Login successful ! ");     one   location.href= "System.php?m=index&a=index";  //  Access Home   } 

Of course, this is the normal mode of access, if it is pathinfo, just need to change the red part as follows

  1   var url= "Dolog";   2  $.post (url,{"staffname":  $staffname , "staffpwd":  $staffpwd , "Verifycode":  $verifycode },  function   (data) {  3   if  (data== " Codeerr ") {  4  alert (" The CAPTCHA is wrong! ");   5 }  else   if  (data== "Authempty" ) {  6  Ale RT ("Please enter your username or password!")               ")   7 }  else   if  (data==" Autherr ") {  8  Alert ("The user name or password is wrong!") ");   9 }  else   if  (data== "Success" ) {  ten  alert ("Login Successful! ");   one   location.href= "...   /index/index ";  //Jump   Home page, methods for accessing other modules  

2. Download the file, always inexplicable many HTML things, because the buffer is not empty, can be modified by the following code, but this way is actually downloaded is still HTML file, but changed the suffix named xls, So when you open with Excel will prompt the format problem, ignore can. Also note that you use the Icov () function to convert the encoding because the XLS default encoding format is not utf-8.

Ob_start (); Ob_end_clean (); Header ("Content-type:application/octet-stream"header("Accept-ranges:bytes"Header ("content-type:application/vnd.ms-excel;charset=gb2312");    Header ("content-disposition:attachment;filename={$filename}.xls");

3. The path problem is encountered when deleting a file, because the project is used more relative path, that is relative to the portal file, but delete the file need to use absolute path, I did not find the appropriate solution, I have to use a more conservative way, the code is as follows

1 $path= "./public/uploads/";     2 $path=str_replace("\ \", "/",realpath($path). " /");  // get the absolute path and convert the delimiter

4. In the configuration of Nginx and PHP, I used the fastcgi way, the following code is saved as a CMD file, directly click to run it.

"F:\php\php-cgi.exe"-B 127.0.0.1:9000-c "F:\php\php.ini"     //followed by the path of the PHP file

Then add a few words to the Nginx configuration file.

1Location ~ \.php/?. * {2 root myapplications;3Fastcgi_pass 127.0.0.1:9000;4Fastcgi_index index.php;5Fastcgi_param Script_filename$document _root$fastcgi_script_name;6            includeFastcgi_params;7 8            #Define variables $path _info, for storing pathinfo information9Set$path _info"";Ten             #Define variables $real _script_name, for storing real addresses OneSet$real _script_name $fastcgi _script_name; A             #if the address matches the regular expression in quotation marks -             if($fastcgi _script_name~ "^ (. +?\.php) (/.+) $") { -                     #assigns a file address to a variable $real _script_name theSet$real _script_name$; -                     #assigns the parameter after the file address to the variable $path _info -Set$path _info$; -             } +             #Configure some parameters for fastcgi -Fastcgi_param Script_filename$document _root$real_script_name; +Fastcgi_param Script_name$real _script_name; AFastcgi_param Path_info$path _info; at}

http://www.bkjia.com/PHPjc/951420.html www.bkjia.com true http://www.bkjia.com/PHPjc/951420.html techarticle in the Nginx configuration thinkphp project, nginxthinkphp project time ago with the Apache with TP developed a small website, also is I use TP of the first combat. I am accustomed to using PathInfo mode ...

  • 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.