php - 新手問題--伺服器環境部署hello world
phpcn_u1582
phpcn_u1582 2017-05-16 13:06:17
0
2
479

為什麼不會顯示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_u1582
phpcn_u1582

全部回覆(2)
洪涛

看下log吧,曾經犯過一個錯誤也是導致PHP不被解析,直接回傳PHP檔並下載。當時的原因是我註釋了PHP轉發,然後瀏覽器請求形成了緩存,當我修改正確配置重啟伺服器後,由於快取原因根本不去請求伺服器。所以你這裡建議你先重啟nginx,清除下瀏覽器緩存,然後看error.log 和 access.log。

大家讲道理

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;
    }
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板