2012-01-25 47 views
16

我的服務器定義有什麼問題?如果我嘗試訪問「www.testing.com」,我會得到一個二進制文件來下載,而不是index.php,而如果我試圖訪問「testing.com」,我會得到index.php。默認使用nginx無法打開index.php

我已經嘗試過服務器名稱設置爲:

servername testing.com; 
servername testing.com www.testing.com; 
servername testing.com www.testing.com *.testing.com; 

相同的行爲:我不能用 「www.testing.com」 得到的index.php,只需用 「testing.com」。 (關閉當然testing.com不是我的只是例如)。

user    nginx; 
    worker_processes 4; 
    error_log   /var/log/nginx/error.log warn; 
    pid    /var/run/nginx.pid; 

    events { 
     worker_connections 1024; 
    } 


    http { 
     include  /etc/nginx/mime.types; 
     default_type text/plain; 

     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; 

     fastcgi_intercept_errors on; 
     sendfile     on; 
     keepalive_timeout   65; 
     gzip      on; 
     index      index.php index.html index.htm; 

     server { 
       listen 80; 
       server_name www.testing.com; 
       root /home/vhosts/testing; 

       location/{ 
        try_files $uri $uri/ /index.php index.php; 
       } 

     location ~* \.(?:ico|css|js|gif|jpe?g|png)$ { 
        expires max; 
        add_header Pragma public; 
        add_header Cache-Control "public, must-revalidate, proxy-revalidate"; 
       } 

     location ~* \.php$ { 
       try_files $uri =404; 
       include fastcgi.conf; 
       fastcgi_pass 127.0.0.1:9000; 
       } 
     } 
    } 

回答

-1

你可以有多個servername行,它會在它們之間建立一個VHOST。

+0

你的意思是他不能? – Purefan

8

location ~* \.php$

location ~* \.php$ { 
       try_files $uri =404; 
       include fastcgi.conf; 
       fastcgi_pass 127.0.0.1:9000; 
       fastcgi_index index.php; 
       } 
+1

+1這爲我工作,謝謝! – coma

18

首先你需要檢查你的php-fpm的設置(也許你使用套接字連接,而不是在你的PHP-FPM配置端口),並默認在您的位置添加索引「/」

location/{ 
    index index.php index.html index.htm; 
    try_files $uri $uri/ =404; 
}