2014-11-03 35 views
2

我在部署Silex項目的服務器上收到此錯誤。FastCGI在stderr中發送:「主要腳本未知」 - nginx和silex

在這個服務器我已經有nginx的傳遞請求從/加入燒瓶中的應用程序在端口上運行5000

所以,從我的倉庫拉新項目/var/www/newproject我試圖nginx的配置經過了這麼一個請求http://xxx.xxx.xxx.xxx/newproject將根目錄爲/var/www/newproject這是一個silex應用程序。

我搜索了網頁,我找到的所有配置都沒有解決我的問題。 訪問任何路線,返回404

我的整個配置是這樣的:

server { 
    listen 80; 
    server_name xxx.xxx.xxx.xxx; 

    access_log /var/log/myproject/nginx_access.log; 
    error_log /var/log/myproject/nginx_error.log; 

    proxy_connect_timeout 300s; 
    proxy_read_timeout 300s; 

    location /newproject { 
     root /var/www; 
     try_files $uri $uri/ =404; 
     index index.php; 
     fastcgi_pass unix:/var/run/php5-fpm.sock; 
     #fastcgi_index index.php; 
     fastcgi_param SCRIPT_FILENAME /var/www/newproject/index.php; 
     #fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
     #fastcgi_param SCRIPT_FILENAME /var/www$fastcgi_script_name; 
     #fastcgi_param SCRIPT_FILENAME /var/www/newproject$fastcgi_script_name; 
     include fastcgi_params; 
    } 

    location/{ 
     root /opt/myproject; 
     proxy_set_header X-Forward-For $proxy_add_x_forwarded_for; 
     proxy_set_header Host $http_host; 
     proxy_redirect off; 
     if (!-f $request_filename) { 
      proxy_pass http://xxx.xxx.xxx.xxx:5000; 
      break; 
     } 
    } 
} 

缺少什麼我在這裏?

謝謝。

UPDATE:

嘗試了新的配置(如下),現在訪問http://xxx.xxx.xxx.xxx/newproject/SOME_PATH我有一個404

open() "/var/www/newproject/SOME_PATH" failed (20: Not a directory) 
open() "/var/www/newproject/index.php/SOME_PATH" failed (20: Not a directory) 

location /newproject { 
     root /var/www/; 
     index index.php index.html index.htm; 
     location ~ ^/newproject/(.+\.php)$ { 
      try_files $uri =404; 
      root /var/www/; 
      fastcgi_pass unix:/var/run/php5-fpm.sock; 
      fastcgi_param HTTPS off; 
      fastcgi_index index.php; 
      #fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
      #fastcgi_param SCRIPT_FILENAME $document_root/index.php; 
      fastcgi_split_path_info ^(.+\.php)(/.+)$; 
      include /etc/nginx/fastcgi_params; 
     } 
     location ~* ^/newproject/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ { 
      root /var/www/; 
     } 

    } 

回答

4

所以,我已經成功地解決我的問題以下這Site Configuration for Nginx Sub-Folder

現在我的配置是:

server { 
    listen 80; 
    server_name xxx.xxx.xxx.xxx; 

    root /opt/myproject; 

    access_log /var/log/myproject/nginx_access.log; 
    error_log /var/log/myproject/nginx_error.log; 

    proxy_connect_timeout 300s; 
    proxy_read_timeout 300s; 

    location /newproject { 
     root /var/www; 
     index index.php index.html index.htm; 
     rewrite ^/newproject/(.*)$ /newproject/$1 break; 
     try_files $uri $uri/ /newproject/index.php?q=$uri&$args; 

     location ~ .*\.php$ { 
      include /etc/nginx/fastcgi_params; 
      fastcgi_pass unix:/var/run/php5-fpm.sock; 
      fastcgi_index index.php; 
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
     } 
    } 

    location/{ 
     root /opt/myproject/; 
     proxy_set_header X-Forward-For $proxy_add_x_forwarded_for; 
     proxy_set_header Host $http_host; 
     proxy_redirect off; 
     if (!-f $request_filename) { 
      proxy_pass http://xxx.xxx.xxxx.xxx:5000; 
      break; 
     } 
    } 
} 

由於新建項目取決於myproject,我將它們的配置保存在同一個文件中,並且具有相同的nginx訪問和錯誤日​​志文件。

2

不要忘了查看用戶:對於nginx的& & PHP-FPM

錯誤信息將成爲同組如果PHP-FPM仍在運行「阿帕奇」用戶,並且已經切換用戶「nginx的」關於nginx的並在http目錄!

and reload both