我正在尝试使用 PHP 和 FPM 设置 NGINX。没有安装错误,NGINX 和 PHP-FPM 正在运行(我可以使用 和 看到它们ps aux | gre nginx
)ps aux | grep php
。HTML 页面运行良好。
当我“查看页面源代码”时,浏览 mysite/test.php 只会显示 PHP 源代码(确实是<? phpinfo(); ?>;
)。我的 NGINX(error.log)或 PHP-FPM(php5-fpm.log)错误日志中没有错误。
我不明白为什么它没有执行代码?
cat sites-enabled/default
server {
root /usr/share/nginx/www;
index index.php index.html index.htm;
server_name testsite.tld;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to index.html
try_files $uri $uri/ /index.html;
}
#error_page 404 /404.html;
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
}
}
cat fastcgi_params
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
答案1
你的 php 代码中有一个类型:
前:
<? phpinfo(); ?>
后:
<?php phpinfo(); ?>
试试看。