Nginx的改掉下载显示的文件,而不是 [英] Nginx trys to download file instead of displaying

查看:163
本文介绍了Nginx的改掉下载显示的文件,而不是的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我安装的Nginx,有一个子域和域。子站点有PHP5-FPM和文字preSS。它工作正常,并且是在一个网站,提供的文件符号链接到网站功能。该域名不具有PHP和具有文件还符号链接。即使重新启动服务器,当我去到域它会尝试下载HTML文件。这里是我的网站,提供页面域:

 服务器{
        SERVER_NAME www.example.us;
        改写^ HTTP://example.us$1永久性的;(*)。
    }

    服务器 {
            听80;
            SERVER_NAME example.us;
                    根/无功/网络/例子。
            指数的index.php;
            自动索引上;
            autoindex_exact_size关闭;
            包括在/ etc / nginx的/安全;
    #记录 - 
    访问日志/var/log/nginx/example.us.access.log;
    是error_log /var/log/nginx/example.us.error.log通知;
            #直接支持静态文件
            位置〜* ^ +。(JPG | JPEG | GIF | CSS | PNG | JS | ICO | HTML | XML | TXT)$ {
                访问日志关闭;
                期满最大;
            }

#位置〜\的.php $ {
#try_files $ URI = 404;
#fastcgi_pass UNIX:/var/run/php5-fpm/example.us.socket;
#fastcgi_index index.php文件;
#包括在/ etc / nginx的/ fastcgi_params;
#}
    }
 

在nginx.conf中的文件是:

 用户WWW的数据;
worker_processes 4;
PID /var/run/nginx.pid;

事件{
    worker_connections 768;
    在#multi_accept;
}
HTTP {
#基本设置
    SENDFILE上;
    tcp_nopush上;
    TCP_NODELAY上;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    #server_tokens关闭;

    #server_names_hash_bucket_size 64;
    #server_name_in_redirect关闭;

    包括/etc/nginx/mime.types;
    default_type文件的应用程序/八位字节流;
#日志设置
log_format GZIP'$ REMOTE_ADDR  -  $ REMOTE_USER [$ time_local]
                '$要求$状态$ bytes_sent
                '$ HTTP_REFERER$ HTTP_USER_AGENT$ gzip_ratio';
    访问日志/var/log/nginx/access.log GZIP缓冲= 32K;
    是error_log /var/log/nginx/error.log通知;
#Gzip已设置
    gzip压缩的;
    gzip_disablemsie6;
    gzip_vary上;
    gzip_proxied任;
    gzip_comp_level 6;
    gzip_buffers 16 8K;
    gzip_http_version 1.1;
    gzip_types文本/纯文本/ css的应用程序/ JSON应用程序/ x-j​​avascript的文/ XML应用程序/ XML应用程序/ XML + RSS文/ JavaScript的;
#虚拟主机的Configs
    包括/etc/nginx/conf.d/*.conf;
    包括在/ etc / nginx的/站点启用/ *;
}
 

解决方案

删除 default_type文件的应用程序/八位字节流; 。此行让浏览器认为这是一些二进制数据,而不是HTML。

I install Nginx and have a subdomain and domain. The subdomain has php5-fpm and wordpress. It works fine and is in one sites-available file symlinked to sites-enabled. The domain doesn't have php and has a file also symlinked. Even after restarting the server when I go to the domain it tries to download the html file. Here is my sites-available page for the domain:

       server {
        server_name www.example.us;
        rewrite ^(.*) http://example.us$1 permanent;
    }

    server {
            listen 80;
            server_name example.us;
                    root /var/www/example;
            index index.php;
            autoindex on;
            autoindex_exact_size off;
            include /etc/nginx/security;
    # Logging --
    access_log /var/log/nginx/example.us.access.log; 
    error_log /var/log/nginx/example.us.error.log notice;
            # serve static files directly
            location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt)$ {
                access_log off;
                expires max;
            }

#            location ~ \.php$ {
#           try_files $uri =404;
#                    fastcgi_pass unix:/var/run/php5-fpm/example.us.socket;
#                    fastcgi_index index.php;
#                    include /etc/nginx/fastcgi_params;
#            }
    }

The nginx.conf file is:

user www-data; 
worker_processes 4; 
pid /var/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
log_format gzip '$remote_addr - $remote_user [$time_local] '
                '"$request" $status $bytes_sent '
                '"$http_referer" "$http_user_agent" "$gzip_ratio"';
    access_log /var/log/nginx/access.log gzip buffer=32k;
    error_log /var/log/nginx/error.log notice;
# 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;
# Virtual Host Configs
    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

解决方案

Remove default_type application/octet-stream;. This lines makes the browser think it's some binary data and not HTML.

这篇关于Nginx的改掉下载显示的文件,而不是的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆