错误200#0:* 79在读取来自上游的响应标题时,在stderr中发送了FastCGI:“主脚本未知”

我想在我的MAC上configuration新的nginx,但我总是得到[error] 200#0: *79 FastCGI sent in stderr: "Primary script unknown" ..我不知道什么我做configuration错误。 这是我的nginx.conf文件:

 #user RobDee; worker_processes auto; #error_log logs/error.log; #error_log logs/error.log info; pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; #log_format #main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; access_log logs/access.log; error_log logs/error.log; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { listen 80; server_name local.mydomain.co.uk local.beer.telegraph.co.uk; #charset koi8-r; #access_log logs/host.access.log main; location / { root /Users/RobDee/workspace/beer/web; index index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server server { listen 443 ; server_name local.mydomain.co.uk local.beer.telegraph.co.uk; ssl on; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_certificate /usr/local/etc/nginx/cert.pem; ssl_certificate_key /usr/local/etc/nginx/cert.key; gzip_disable "msie6"; gzip_types text/plain application/xml application/x-javascript text/css application/json text/javascript; access_log /usr/local/var/log/nginx/access.log; error_log /usr/local/var/log/nginx/error.log; log_not_found off; root /Users/RobDee/workspace/beer/web; location /.htpasswd { return 403; } location ~ \.css { root /Users/RobDee/workspace/beer/web; expires max; } location ~* \.(jpg|jpeg|png|gif|ico|js|woff|woff2|ttf)$ { root /Users/RobDee/workspace/beer/web; access_log off; expires max; } location ~* \.(js|css)$ { expires 1y; log_not_found off; } location / { root /Users/RobDee/workspace/beer/web; try_files $uri $uri/ /app_dev.php$is_args$args; index app_dev.php; } location ~ \.php$ { root /Users/RobDee/workspace/beer/web; fastcgi_pass 127.0.0.1:9000; fastcgi_index /Users/RobDee/workspace/beer/web/app_dev.php; fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; include fastcgi_params; fastcgi_read_timeout 3000; } } include servers/*; } 

也许有人会在我的conf中看到一些错误。

“主脚本未知”几乎总是意味着SCRIPT_FILENAME的值是错误的。

问题可能是这三行:

 root /Users/RobDee/workspace/beer/web; fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; include fastcgi_params; 

您设置$document_root ,然后将其作为/scripts硬连线。 这是哪个?

在一个普通的nginx服务器块中,你可以在服务器块顶部附近设置一次root ,并允许所有(或大部分) location块inheritance相同的值。 只有在必要时才能覆盖 详情请参阅此文件 。

SCRIPT_FILENAME的通常格式是以下任一种:

 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_FILENAME $request_filename; 

在你的configuration中哪一个将等同于相同的值。 注意$document_rootroot指令的值定义。

最后,包括fastcgi_params在内的最后可能会也可能不会。 在fastcgi_params某些版本中,可能存在您明确定义的fastcgi_param语句的冲突定义。 您应该始终在明确的fastcgi_param语句之前包含该文件。

例如:

 server { ... root /Users/RobDee/workspace/beer/web; ... location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $request_filename; fastcgi_read_timeout 3000; } } 

fastcgi_index指令在这个上下文中没有意义。