用nginx默认不能打开index.php

我的服务器定义有什么问题? 如果我尝试访问“www.testing.com”,我得到一个二进制文件,而不是index.php,而如果我尝试访问“testing.com”,我得到的index.php。

我已经尝试将servername设置为:

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

同样的行为:我不能得到index.php与“www.testing.com”,只是与“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; } } } 

首先你需要检查你的php-fpm设置(也许你在你的php-fpm配置中使用套接字连接而不是端口)并且在你的位置默认添加索引“/”

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

添加fastcgi_index index.php;location ~* \.php$

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

检查你的FPM正在运行,并在127.0.0.1:9000

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

也记录错误和检查

  error_log /var/log/nginx/error.log debug; 

对于示例conf检查https://github.com/rtCamp/easyengine/blob/master/conf/nginx/singlesite/basic.conf

你可以有多个servername行,它会在所有行上建立一个VHOST。