2014-01-14 45 views
0

我有一個NGINX讓我瘋了。我在VirtualBox上安裝了Ubuntu 12.04.3 LTS。我按照這些說明安裝NGINX,MYSQL,PHP:NGINX顯示腳本代碼而不是執行

  1. 安裝PHP5 -FPM;
  2. set cgi.fix_pathinfo = 0 in /etc/php5/fpm/php.ini;
  3. 設置聽= VAR /運行/ PHP5-fpm.sock/etc/php5/fpm/pool.d/www.conf

然後我在設置的/ etc/nginx的/網站可用/默認

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

兩個本地主機info.php的被正確執行。現在我想建立一個本地網站,並嘗試做一些重定向。所以,我在在/ usr /共享創建一個新的文件夾,名爲mywebsite/nginx的/ WWW,把的index.php內有回聲指令,PHP腳本我做重定向到,在增加了一個新的配置文件網站可用該鏈接網站啓用,爲了避免下載腳本文件中nginx.conf禁用應用程序/八位字節流。所以我設置我的新配置文件如下:

server { 
    listen 80; 

    root /usr/share/nginx/www/mysite; 
    index index.php index.html index.htm; 

    server_name www.mysite.com; 

    location/{ 
     try_files $uri $uri/ /index.html; 
     if (!-e $request_filename){ 
     rewrite ^/location/([0-9]+)/device/([0-9]+)/senseddata/$ /senseddata.php break; 
     rewrite ^/location/([0-9]+)/device/([0-9]+)/senseddata/lasthour/$ /senseddata.php break; 
     rewrite ^/location/([0-9]+)/device/([0-9]+)/senseddata/daily/$ /senseddata.php break; 
     } 
    } 

    error_page 404 /404.html; 
    error_page 500 502 503 504 /50x.html; 

    location = /50x.html { 
     root /usr/share/nginx/www; 
    } 

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 
    location ~ \.php$ { 
     fastcgi_pass unix:/var/run/php5-fpm.sock; 
     fastcgi_index index.php; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
     include fastcgi_params; 
     try_files $uri =404; 
    } 

    # deny access to .htaccess files, if Apache's document root 
    # concurs with nginx's one 
    # 
    location ~ /\.ht { 
    deny all; 
    } 
} 

那麼究竟發生了什麼? Index.php正確執行。重寫很好,但腳本沒有執行。我只能看到我寫的全部代碼顯示在瀏覽器中。有什麼問題?提前致謝。

+0

你的nginx工作是獨立的還是與Apache的反向代理?看起來像你的nginx沒有一個有效的PHP處理程序 –

+0

當你運行'sudo服務php5-fpm status'時,你會得到什麼? –

+0

感謝您的回答。 NGINX單獨工作,並且php5-fpm狀態正在運行。順便說一下,我解決了在重寫行中最後寫入BREAK的問題。我不知道這兩個詞的區別(也許有人可以解釋),但它解決了這個問題。這很好。非常感謝你。 –

回答

0

嘗試添加fastcgi_split_path_info ^(.+\.php)(/.+)$;location ~ \.php$並重新啓動nginx。

實例從我的配置

location ~ \.php$ { 
    fastcgi_split_path_info ^(.+\.php)(/.+)$; 
    try_files $uri =404; 
    fastcgi_pass unix:/var/run/php5-fpm.sock; 
    fastcgi_index index.php; 
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
    include fastcgi_params; 
} 
+0

我有同樣的問題,和我的配置文件相同,你提到,仍然不工作 –

0

同時檢查開始標籤在你的PHP-文件。如果您使用<?而不是<?php,並且short tag不可用,則不會解析PHP代碼,您將看到源代碼。

相關問題