2013-04-26 143 views
5

我安装了Nginx并且有一个子域和域。该子域有php5-fpm和wordpress。它工作正常,并且在一个站点可用文件符号链接到启用站点。该域没有PHP,并且有一个文件也符号链接。即使在重新启动服务器后,当我尝试下载html文件时,它也会尝试下载该文件。这里是我的地盘 - 可用的页面域:Nginx试图下载文件而不是显示

 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; 
#   } 
    } 

的nginx.conf文件是:

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/*; 
} 
+0

好的,现在我更加困惑了。我在AWS上运行一个实例。我关闭了实例,我仍然可以下载文件。所以,这不应该发生。 – moosilauke18 2013-04-26 05:02:44

回答

5

删除default_type application/octet-stream;。这一行使浏览器认为它是一些二进制数据而不是HTML。

+0

我在评论default_type后仍然有相同的问题,还有其他建议吗?在我的例子中, – 2013-08-15 08:34:58

+0

问题在于php没有安装。安装之后,我必须让php-fpm监听正确的主机/端口。在/etc/php5/fpm/pool.d/www.conf中将以下行更改为:listen = /var/run/php5-fpm.sock 收件人: listen = 127.0.0.1:9000 重新启动php-fpm sudo /etc/init.d/php5-fpm restart,一切都应该起作用。 Goodluck,看看这个链接的额外帮助http://wildlyinaccurate.com/solving-502-bad-gateway-with-nginx-php-fpm – 2013-08-16 10:19:38

+3

@ArminNehzat Nginx提供的文件,而不是php-fpm,这就是为什么它是下载。找出为什么这个文件是通过Nginx直接发送的,而不是通过php-fpm发送的。 – Gustav 2013-08-16 15:12:22

相关问题