Nginx
error 200#0: *79 FastCGI sent in stderr: ‘Primary script unknown’ 同時從上游讀取響應標頭,
我想在我的 MAC 上配置新的 nginx,但我總是得到
[error] 200#0: *79 FastCGI sent in stderr: "Primary script unknown"
.. 我不知道我在配置上做錯了什麼。這是我的 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 中看到一些錯誤。
“主腳本未知”幾乎總是意味著 for 的值
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
塊繼承相同的值。僅在必要時覆蓋。有關詳細資訊,請參閱此文件。通常的格式
SCRIPT_FILENAME
是以下之一:fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_FILENAME $request_filename;
在您的配置中,這將等同於相同的值。請注意,這
$document_root
是由root
指令的值定義的。最後,包括
fastcgi_params
last 可能會也可能不會。在某些版本中,您明確定義的語句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
指令在這種情況下沒有任何意義。