search

Home  >  Q&A  >  body text

php - Newbie question--server environment deployment 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_u15822816 days ago483

reply all(2)I'll reply

  • PHP中文网

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

    Look at the log. I once made a mistake that also caused PHP not to be parsed, and the PHP file was directly returned and downloaded. The reason at that time was that I commented PHP forwarding, and then the browser request formed a cache. When I modified the correct configuration and restarted the server, the server was not requested at all due to caching reasons. So it is recommended that you restart nginx first, clear the browser cache, and then look at the error.log and access.log.

    reply
    0
  • 大家讲道理

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

    nginx does not support PHP parsing:

    The nginx.conf configuration file under Baidu supports 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;
        }

    reply
    0
  • Cancelreply