微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

为什么下载index.php而不是Nginx呈现?

我现在已经敲了两天头.问题是index.PHP是下载而不是被处理.我正在使用Ubuntu 14.04,Nginx,PHP5. Nginx / site-available / default如下所示.我添加了许多帖子规定的index.PHP条目.

    server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /usr/share/Nginx/html;
    index index.PHP index.html index.htm;

    # Make site accessible from http://localhost/
    server_name localhost;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
        # Uncomment to enable naxsi on this location
        # include /etc/Nginx/naxsi.rules
    }


    # Only for Nginx-naxsi used with Nginx-naxsi-ui : process denied requests
    #location /RequestDenied {
    #   proxy_pass http://127.0.0.1:8080;    
    #}

    #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_split_path_info ^(.+\.PHP)(/.+)$;
    #   # NOTE: You should have "cgi.fix_pathinfo = 0;" in PHP.ini
    #
    #   # With PHP5-cgi alone:
    #   fastcgi_pass 127.0.0.1:9000;
    #   # With PHP5-fpm:
    #   fastcgi_pass unix:/var/run/PHP5-fpm.sock;
    #   fastcgi_index index.PHP;
    #   include fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with Nginx's one
    #
    #location ~ /\.ht {
    #   deny all;
    #}
}



    #server {
    #   listen 8000;
    #   listen somename:8080;
    #   server_name somename alias another.alias;
    #   root html;
    #   index index.PHP index.html index.htm;
    #
    #   location / {
    #       try_files $uri $uri/ =404;
    #   }
    #}


    # HTTPS server
    #
    #server {
    #   listen 443;
    #   server_name localhost;
    #
    #   root html;
    #   index index.PHP index.html index.htm;
    #
    #   ssl on;
    #   ssl_certificate cert.pem;
    #   ssl_certificate_key cert.key;
    #
    #   ssl_session_timeout 5m;
    #
    #   ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
    #   ssl_ciphers "HIGH:!aNULL:!MD5 or HIGH:!aNULL:!MD5:!3DES";
    #   ssl_prefer_server_ciphers on;
    #
    #   location / {
    #       try_files $uri $uri/ =404;
    #   }
    #}

Nginx.conf如下所示..

user www-data;
worker_processes 4;
pid /run/Nginx.pid;

events {
    worker_connections 768;
    # multi_accept on;
    }

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

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

    ##
    # Logging Settings
    ##

    access_log /var/log/Nginx/access.log;
    error_log /var/log/Nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;
    gzip_disable "msie6";

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+RSS text/javascript;

    ##
    # Nginx-naxsi config
    ##
    # Uncomment it if you installed Nginx-naxsi
    ##

    #include /etc/Nginx/naxsi_core.rules;

    ##
    # Nginx-passenger config
    ##
    # Uncomment it if you installed Nginx-passenger
    ##

    #passenger_root /usr;
    #passenger_ruby /usr/bin/ruby;

    ##
    # Virtual Host Configs
    ##

    include /etc/Nginx/conf.d/*.conf;
    include /etc/Nginx/sites-enabled/*;
}


#mail {
#   # See sample authentication script at:
#   # http://wiki.Nginx.org/ImapAuthenticateWithApachePHPScript
# 
#   # auth_http localhost/auth.PHP;
#   # pop3_capabilities "TOP" "USER";
#   # imap_capabilities "IMAP4rev1" "UIdplUS";
# 
#   server {
#       listen     localhost:110;
#       protocol   pop3;
#       proxy      on;
#   }
# 
#   server {
#       listen     localhost:143;
#       protocol   imap;
#       proxy      on;
#   }
#}

解决方案一直到现在.

>添加了index.PHP的条目
>删除行default_type application / octet-stream;在
Nginx.conf
>取消注释文件中的fastcgi条目.

我也针对同样的问题尝试了这些解决方案,但它们对我不起作用.

> https://stackoverflow.com/questions/16747980/nginx-and-php-fpm-is-downloading-index-php-instead-of-processing-it
>在堆栈溢出上再添加一个类似链接链接
网站.

解决方法:

有时它可以像清除浏览器缓存一样简单.如果存在一些配置错误并确实正在下载文件,则在修复配置后,需要告知浏览器停止使用缓存下载.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐