2013-06-19 42 views
8

我第一次使用Nginx,但我比Apache和Linux更熟悉。我正在使用一個現有的項目,當我試圖看到index.php時,我得到一個404文件未找到。1 FastCGI發送stderr:「主腳本未知」

這裏是access.log的條目:

2013/06/19 16:23:23 [error] 2216#0: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 127.0.0.1, server: localhost, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "www.ordercloud.lh" 

這裏是網站可用文件:

server { 
# Listening on port 80 without an IP address is only recommended if you are not running multiple v-hosts 
    listen  80; 
# Bind to the public IP bound to your domain 
#listen 127.0.0.11:80; 
# Specify this vhost's domain name 
    server_name www.ordercloud.lh; 
    root /home/willem/git/console/frontend/www; 
    index index.php index.html index.htm; 

# Specify log locations for current site 
    access_log /var/log/access.log; 
    error_log /var/log/error.log warn; 

# Typically I create a restrictions.conf file that I then include across all of my vhosts 
#include conf.d/restrictions.conf; 
# I've included the content of my restrictions.conf in-line for this example 

# BEGIN restrictions.conf 
# Disable logging for favicon 
    location = /favicon.ico { 
     log_not_found off; 
     access_log off; 
    } 

# Disable logging for robots.txt 
    location = /robots.txt { 
     allow all; 
     log_not_found off; 
     access_log off; 
    } 

# Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac). 
    location ~ /\. { 
     deny all; 
     access_log off; 
     log_not_found off; 
    } 
# END restrictions.conf 

# Typically I create a yiiframework.conf file that I then include across all of my yii vhosts 
#include conf.d/yiiframework.conf; 
# I've included the content of my yiiframework.conf in-line for this example 

# BEGIN yiiframework.conf 
# Block access to protected, framework, and nbproject (artifact from Netbeans) 
    location ~ /(protected|framework|nbproject) { 
     deny all; 
     access_log off; 
     log_not_found off; 
    } 

# Block access to theme-folder views directories 
    location ~ /themes/\w+/views { 
     deny all; 
     access_log off; 
     log_not_found off; 
    } 

# Attempt the uri, uri+/, then fall back to yii's index.php with args included 
# Note: old examples use IF statements, which nginx considers evil, this approach is more widely supported 
    location/{ 
     try_files $uri $uri/ /index.php?$args; 
    } 
# END yiiframework.conf 

# Tell browser to cache image files for 24 hours, do not log missing images 
# I typically keep this after the yii rules, so that there is no conflict with content served by Yii 
    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ { 
     expires 24h; 
     log_not_found off; 
    } 

# Block for processing PHP files 
# Specifically matches URIs ending in .php 
    location ~ \.php$ { 
     try_files $uri =404; 
     fastcgi_intercept_errors on; 
# Fix for server variables that behave differently under nginx/php-fpm than typically expected 
     #fastcgi_split_path_info ^(.+\.php)(/.+)$; 
# Include the standard fastcgi_params file included with nginx 
     include fastcgi_params; 
     #fastcgi_param PATH_INFO  $fastcgi_path_info; 
     #fastcgi_index index.php; 
# Override the SCRIPT_FILENAME variable set by fastcgi_params 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
# Pass to upstream PHP-FPM; This must match whatever you name your upstream connection 
     fastcgi_pass 127.0.0.1:9000; 

    } 
} 

/home/willem/git/console由www數據資:WWW的數據(我的網絡用戶運行的PHP等),我已經給它777權限出於無奈...

任何人都可以建議嗎?

+0

什麼你想調用的URL? –

+0

我覺得serverfault的人會更適合幫忙。 –

+0

正確設置php-fpm訪問日誌。重要的是%f在那裏,所以你可以看到它試圖執行的腳本路徑。試試這個:'access.format =「%R - %u%t」%m%r%Q%q \「%s%f%{mili} d%{kilo} M%C %%」'。然後在你的問題中發佈結果。 – Melvyn

回答

5

好了,三件事情我掙扎

  1. 出於某種原因,一整天后,發現我已經有一些在端口9000,所以我 改爲9001
  2. 我的默認網站被攔截我的新的運行,再次我不支持 爲什麼因爲它不應該,但我只是取消了鏈接
  3. Nginx不會自動爲站點提供sym鏈接 - 可用於啓用站點的 。

希望這可以節省一些人的麻煩!

這裏是服務器故障更詳細的鏈接:https://serverfault.com/questions/517190/nginx-1-fastcgi-sent-in-stderr-primary-script-unknown/517207#517207

7

從FastCGI的服務器,即消息通常意味着SCRIPT_FILENAME,它被賦予找不到或無法訪問作爲其文件系統中的文件。在/home/willem/git/console/frontend/www/index.php

結帳文件權限

它是644?

和/ home /威廉/ git的/控制檯/前端/ WWW/

它是755?

+0

原來是一個端口錯誤,但我得到它排序謝謝! – We0

+0

什麼是遞歸設置所有目錄和文件的快速方法? –

+0

完整答案在這裏:https://superuser.com/a/91938 –

5

如果人有同樣的錯誤:在我的情況下,問題是nginx.conf位置塊內丟失的根指令,as explained in the Arch wiki

+0

這解決了它對我來說,謝謝! –

1

我不知道$ DOCUMENT_ROOT是如何計算的,但我解決了問題通過 真正確保我的文檔根目錄是/ usr /共享/ nginx的/剛剛wher的HTML文件夾中存在

0

「主腳本未知」SELinux安全方面造成的。

客戶得到的迴應

File not found.

nginx的錯誤。日誌具有以下錯誤消息

*19 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream

所以只是改變Web根文件夾的安全上下文類型httpd_sys_content_t

chcon -R -t httpd_sys_content_t /var/www/show




有3個用戶爲nginx的/ PHP-FPM配置

/etc/nginx/nginx.conf

user nobody nobody; ### `user-1`, this is the user run nginx woker process 
... 
include servers/*.conf; 

/etc/nginx/servers/www.conf

location ~ \.php$ { 
# fastcgi_pass 127.0.0.1:9000; # tcp socket 
    fastcgi_pass unix:/var/run/php-fpm/fpm-www.sock; # unix socket 
    fastcgi_index index.php; 
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
    include fastcgi_params; 
} 

/etc/php-fpm.d/www.conf

[www] 
user = apache ### `user-2`, this is the user run php-fpm pool process 
user = apache 

;listen = 127.0.0.1:9000 # tcp socket 
listen = /var/run/php-fpm/fpm-www.sock # unix socket 

listen.onwer = nobody ### `user-3`, this is the user for unix socket, like /var/run/php-fpm/fpm-www.sock 
listen.group = nobody # for tcp socket, these lines can be commented 
listen.mode = 0660 

用戶1和user-2不必相同。

對於Unix套接字,用戶1需要是相同的用戶3, 如nginx的fastcgi_pass必須具有讀取Unix套接字上/寫權限。

否則nginx的會得到502網關錯誤,和nginx的error.log中有以下錯誤消息

*36 connect() to unix:/var/run/php-fpm/fpm-www.sock failed (13: Permission denied) while connecting to upstream

相關問題