我有一個NGINX讓我瘋了。我在VirtualBox上安裝了Ubuntu 12.04.3 LTS。我按照這些說明安裝NGINX,MYSQL,PHP:NGINX顯示腳本代碼而不是執行
- 安裝PHP5 -FPM;
- set cgi.fix_pathinfo = 0 in /etc/php5/fpm/php.ini;
- 設置聽= 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正確執行。重寫很好,但腳本沒有執行。我只能看到我寫的全部代碼顯示在瀏覽器中。有什麼問題?提前致謝。
你的nginx工作是獨立的還是與Apache的反向代理?看起來像你的nginx沒有一個有效的PHP處理程序 –
當你運行'sudo服務php5-fpm status'時,你會得到什麼? –
感謝您的回答。 NGINX單獨工作,並且php5-fpm狀態正在運行。順便說一下,我解決了在重寫行中最後寫入BREAK的問題。我不知道這兩個詞的區別(也許有人可以解釋),但它解決了這個問題。這很好。非常感謝你。 –