网站换皮肤了
nginx+php+ThinkPHP环境常见错误总结
时间:2018-05-14 12:45 浏览:1208

摘要

none

错误一

2017/09/07 16:39:18 [error] 21753#0: *26 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.31.26.114, server: localhost, request: "GET /1.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "10.200.8.220:8000"

解决版本

在server节点下添加以下配置

root   /var/www/web;
index  index.php index.html index.htm;
location ~ \.php$ {
	try_files $uri = 404;
	fastcgi_pass   127.0.0.1:9000;
	fastcgi_index  index.php;
	fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
	include        fastcgi.conf;
}

ThinkPHP配置

假如网站的根目录是/var/www/web,如果ThinkPHP的网站在/var/www/web/Test目录配置如下

        location /Test/ {
            if (!-e $request_filename){
                rewrite ^/Test/(.*)$ /Test/index.php?s=$1 last;
            }
        }

        location ~ \.php/?.*$ {
            try_files $uri = 404;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include        fastcgi.conf;
            #设置PATH_INFO并改写SCRIPT_FILENAME,SCRIPT_NAME服务器环境变量  
            #set $fastcgi_script_name2 $fastcgi_script_name;  
            #if ($fastcgi_script_name ~ "^(.+\.php)(/.+)$") {  
            #    set $fastcgi_script_name2 $1;  
            #    set $path_info $2;  
            #}  
            #fastcgi_param   PATH_INFO $path_info;  
            #fastcgi_param   SCRIPT_FILENAME   $document_root$fastcgi_script_name2;  
            #fastcgi_param   SCRIPT_NAME   $fastcgi_script_name2; 
        }

如果是放在根目录下

        location / {
            if (!-e $request_filename){
                rewrite ^/(.*)$ /index.php?s=$1 last;
            }
        }

        location ~ \.php/?.*$ {
            try_files $uri = 404;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include        fastcgi.conf;
            #设置PATH_INFO并改写SCRIPT_FILENAME,SCRIPT_NAME服务器环境变量  
            #set $fastcgi_script_name2 $fastcgi_script_name;  
            #if ($fastcgi_script_name ~ "^(.+\.php)(/.+)$") {  
            #    set $fastcgi_script_name2 $1;  
            #    set $path_info $2;  
            #}  
            #fastcgi_param   PATH_INFO $path_info;  
            #fastcgi_param   SCRIPT_FILENAME   $document_root$fastcgi_script_name2;  
            #fastcgi_param   SCRIPT_NAME   $fastcgi_script_name2; 
        }

最后来个完整的例子

user  root;
worker_processes  auto;
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
#pid        logs/nginx.pid;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  localhost;
        root   /var/www/web;
        index  index.php index.html index.htm;
        location / {
        index  index.htm index.html index.php;  
        }
        location /Test/ {
            if (!-e $request_filename){
                rewrite ^/Test/(.*)$ /Test/index.php?s=$1 last;
            }
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        location ~ \.php/?.*$ {
            try_files $uri = 404;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include        fastcgi.conf;
            #设置PATH_INFO并改写SCRIPT_FILENAME,SCRIPT_NAME服务器环境变量  
            #set $fastcgi_script_name2 $fastcgi_script_name;  
            #if ($fastcgi_script_name ~ "^(.+\.php)(/.+)$") {  
            #    set $fastcgi_script_name2 $1;  
            #    set $path_info $2;  
            #}  
            #fastcgi_param   PATH_INFO $path_info;  
            #fastcgi_param   SCRIPT_FILENAME   $document_root$fastcgi_script_name2;  
            #fastcgi_param   SCRIPT_NAME   $fastcgi_script_name2; 
        }
    }
}

               



如果这篇文章对你有所帮助,可以通过下边的“打赏”功能进行小额的打赏。

本网站部分内容来源于互联网,如有侵犯版权请来信告知,我们将立即处理。


来说两句吧