suchen

Heim  >  Fragen und Antworten  >  Hauptteil

php - 新手问题--服务器环境部署hello world

为什么不会显示hello world,而是下载了一个php文件

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections  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;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;
    server {
          listen       80;
          root   /usr/share/nginx/html;
          server_name  localhost;

          #charset koi8-r;
          #access_log  /var/log/nginx/log/host.access.log  main;

          location / {
              index  index.html index.htm;
          }

          #error_page  404              /404.html;

          # redirect server error pages to the static page /50x.html
          #
          error_page   500 502 503 504  /50x.html;
          location = /50x.html {
                root   /usr/share/nginx/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;
                fastcgi_param  SCRIPT_FILENAME        $document_root$fastcgi_script_name;
                include        fastcgi_params;
         }
    }
}
phpcn_u1582phpcn_u15822861 Tage vor509

Antworte allen(2)Ich werde antworten

  • PHP中文网

    PHP中文网2017-05-16 13:08:17

    看下log吧,曾经犯过一个错误也是导致PHP不被解析,直接返回PHP文件并下载。当时的原因是我注释了PHP转发,然后浏览器请求形成了缓存,当我修改正确配置重启服务器后,由于缓存原因根本不去请求服务器。所以你这里建议你先重启nginx,清除下浏览器缓存,然后看下error.log 和 access.log。

    Antwort
    0
  • 大家讲道理

    大家讲道理2017-05-16 13:08:17

    nginx没有支持PHP解析:

    你百度下 nginx.conf 配置文件对PHP的支持

    location ~ .php$ {

               root /usr/local/nginx/html; #指定php的根目录
               fastcgi_pass 127.0.0.1:9000;#php-fpm的默认端口是9000
               fastcgi_index index.php;
               fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
               include fastcgi_params;
        }

    Antwort
    0
  • StornierenAntwort