2013-04-26 38 views
5

Tôi cài đặt Nginx và có tên miền phụ và miền. Tên miền phụ có php5-fpm và wordpress. Nó hoạt động tốt và nằm trong một trang web có sẵn tập tin symlinked để các trang web kích hoạt. Miền không có php và có một tệp cũng được liên kết với nhau. Ngay cả sau khi khởi động lại máy chủ khi tôi đi đến miền nó cố gắng tải xuống tệp html. Đây là trang sites-available tôi cho tên miền:Nginx trys để tải xuống tệp thay vì hiển thị

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

File nginx.conf là:

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

Ok, giờ tôi còn bối rối hơn nữa. Tôi đang trên AWS chạy một ví dụ. Tôi tắt máy và tôi vẫn có thể tải xuống tệp. Vì vậy, điều này không nên xảy ra. – moosilauke18

Trả lời

5

Di default_type application/octet-stream;. Dòng này làm cho trình duyệt nghĩ rằng đó là một số dữ liệu nhị phân chứ không phải HTML.

+0

Tôi vẫn gặp sự cố tương tự sau khi nhận xét về default_type, mọi đề xuất khác? –

+0

trong trường hợp của tôi vấn đề là php chưa được cài đặt. Sau khi cài đặt nó, tôi phải lấy php-fpm để nghe trên máy chủ/cổng chính xác. Trong /etc/php5/fpm/pool.d/www.conf thay đổi dòng sau từ: listen = /var/run/php5-fpm.sock Đến: listen = 127.0.0.1:9000 Khởi động lại php-fpm với sudo /etc/init.d/php5-fpm khởi động lại và mọi thứ sẽ hoạt động. Goodluck và xem liên kết này để được trợ giúp thêm http://wildlyinaccurate.com/solving-502-bad-gateway-with-nginx-php-fpm –

+3

@ArminNehzat Nginx phục vụ tệp chứ không phải php-fpm, đó là lý do tại sao tải xuống. Tìm hiểu lý do tại sao tệp được gửi trực tiếp với Nginx và không thông qua php-fpm. – Gustav

Các vấn đề liên quan