默认情况下无法使用Nginx打开index.php [英] Can't open index.php by default with nginx

查看:715
本文介绍了默认情况下无法使用Nginx打开index.php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的服务器定义有什么问题?如果我尝试访问"www.testing.com",我将下载二进制文件而不是index.php,相反,如果我尝试访问"testing.com",我将获得index.php.

What's wrong with my server definition? If I try to access to "www.testing.com" I get a binary to download instead of the index.php, instead if I try to access to "testing.com" I get the index.php.

我已经尝试将服务器名设置为:

I already tried to set servername to:

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

相同的行为:我无法通过"www.testing.com"获得index.php,而只能通过"testing.com"获得index.php. (当然,testing.com当然不是我的.)

Same behavior: I can't get index.php with "www.testing.com", just with "testing.com". (off course testing.com is not mine is just for example).

    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配置中使用套接字连接而不是端口),并在默认情况下在其中添加索引位置"/"

first you need to check your php-fpm settings (maybe you using socket connection instead of port in your php-fpm configuration) and add index by default in your location "/"

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

这篇关于默认情况下无法使用Nginx打开index.php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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