鍍金池/ 問(wèn)答/Linux/ nginx無(wú)法解析PHP程序,一開(kāi)啟網(wǎng)頁(yè)就直接下載PHP程序

nginx無(wú)法解析PHP程序,一開(kāi)啟網(wǎng)頁(yè)就直接下載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 /run/nginx.pid;

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 default_server;
        listen       [::]:80 default_server;
        server_name  _;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }
}

代碼已貼上,環(huán)境是阿里云上的集成環(huán)境,如何解決(403頁(yè)面并自動(dòng)下載)

回答
編輯回答
憶往昔

/etc/nginx/default.d 目錄下的配置文件什么內(nèi)容??

不過(guò)不管是什么內(nèi)容,都沒(méi)有看到:

location ~ \.php(.*) {
    fastcgi_pass 127.0.0.1:9000;
    .....
}

這樣的代碼,說(shuō)明你沒(méi)有設(shè)置如果碰到類(lèi)似 index.phptest.php 這樣的以 .php(.*) 結(jié)尾文件時(shí)的處理方式!

當(dāng)然他就會(huì)當(dāng)成是不認(rèn)識(shí)的文件進(jìn)行下載了。

2018年4月3日 17:23
編輯回答
小曖昧

Nginx和PHP是通過(guò)FastCGI的

location ~ \.php {
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_split_path_info ^(.+\.php)(.*)$;
    fastcgi_param PATH_INFO $fastcgi_path_info;
    include fastcgi_params;
}
2018年1月30日 23:03
編輯回答
舊顏

Nginx是服務(wù)器,主要用來(lái)處理HTTP請(qǐng)求,其本身并不支持解析運(yùn)行PHP代碼的能力,需要配合php-fpm來(lái)運(yùn)行php代碼。

從題主上面貼出的配置,還不能準(zhǔn)確判斷出問(wèn)題所在,需要知道
include /etc/nginx/default.d/*.conf; 這個(gè)文件下的配置文件內(nèi)容。

2018年3月10日 22:28
編輯回答
不舍棄

可以參考下這里《Centos 7 php 環(huán)境安裝及配置》,應(yīng)該是沒(méi)配置好

2018年4月2日 08:56
編輯回答
寫(xiě)榮

因?yàn)?nginx 默認(rèn)并不支持 PHP 等動(dòng)態(tài)語(yǔ)言。可是使用 fastcgi 來(lái)使用 PHP。

可以參考一下這個(gè)教程:https://segmentfault.com/a/1190000003067656

2017年4月12日 00:15