< /p>
< /p>
為什么不會(huì)顯示hello world,而是下載了一個(gè)php文件
# 有關(guān)配置的更多信息,請(qǐng)參閱:
# * 官方英文文檔:http://nginx.org/en/docs/
# * 俄語官方文檔:http://nginx.org/ru/docs/
用戶 nginx;
自動(dòng)worker_processes;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
# 加載動(dòng)態(tài)模塊。請(qǐng)參閱/usr/share/nginx/README.dynamic。
包含/usr/share/nginx/modules/*.conf;
事件{
工人連接1024;
}
http{
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 /var/log/nginx/access.log main;
發(fā)送文件;
tcp_nopush 開啟;
tcp_nodelay 開啟;
keepalive_timeout 65;
types_hash_max_size 2048;
包括/etc/nginx/mime.types;
default_type 應(yīng)用程序/八位字節(jié)流;
# 從 /etc/nginx/conf.d 目錄加載模塊化配置文件。
# 參見http://nginx.org/en/docs/ngx_core_module.html#include
# 了解更多信息。
包括/etc/nginx/conf.d/*.conf;
服務(wù)器 {
聽80;
根/usr/share/nginx/html;
服務(wù)器名稱本地主機(jī);
#字符集 koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
地點(diǎn) / {
索引index.htmlindex.htm;
}
#error_page 404 /404.html;
# 將服務(wù)器錯(cuò)誤頁面重定向到靜態(tài)頁面/50x.html
#
error_page 500 502 503 504 /50x.html;
位置= /50x.html {
根/usr/share/nginx/html;
}
# 將 PHP 腳本傳遞給監(jiān)聽 127.0.0.1:9000 的 FastCGI 服務(wù)器
#
位置 ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index索引.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
包括 fastcgi_params;
}
}
}
看下log吧,曾經(jīng)犯過一個(gè)錯(cuò)誤也是導(dǎo)致PHP不被解析,直接返回PHP文件并下載。當(dāng)時(shí)的原因是我注釋了PHP轉(zhuǎn)發(fā),然后瀏覽器請(qǐng)求形成了緩存,當(dāng)我修改正確配置重啟服務(wù)器后,由于緩存原因根本不去請(qǐng)求服務(wù)器。所以你這里建議你先重啟nginx,清除下瀏覽器緩存,然后看下error.log 和 access.log。
nginx沒有支持PHP解析:
你百度下 nginx.conf 配置文件對(duì)PHP的支持
location ~ .php$ {
root /usr/local/nginx/html; #指定php的根目錄
fastcgi_pass 127.0.0.1:9000;#php-fpm的默認(rèn)端口是9000
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}