首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >nginx默认情况下无法打开index.php

nginx默认情况下无法打开index.php
EN

Stack Overflow用户
提问于 2012-01-25 19:52:04
回答 5查看 61.2K关注 0票数 22

我的服务器定义有什么问题?如果我试图访问"www.testing.com“,我得到的是要下载的二进制文件,而不是index.php;相反,如果我试图访问"testing.com”,我得到的是index.php。

我已经尝试将servername设置为:

代码语言:javascript
复制
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不是我的,例如)。

代码语言:javascript
复制
    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;
              }
         }
    }
EN

回答 5

Stack Overflow用户

发布于 2015-02-08 03:49:47

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

代码语言:javascript
复制
location / {
    index index.php index.html index.htm;
    try_files $uri $uri/ =404;
}
票数 24
EN

Stack Overflow用户

发布于 2013-05-25 18:07:02

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

代码语言:javascript
复制
location ~* \.php$ {
    try_files $uri =404;
    include fastcgi.conf;
    fastcgi_pass  127.0.0.1:9000;
    fastcgi_index  index.php;
}
票数 8
EN

Stack Overflow用户

发布于 2013-05-25 18:16:06

检查fpm是否在127.0.0.1:9000上运行

代码语言:javascript
复制
location ~ \.php$ {
     try_files $uri =404;
     include fastcgi.conf;
     fastcgi_pass  127.0.0.1:9000;
}

还要记录错误并进行检查:

代码语言:javascript
复制
error_log  /var/log/nginx/error.log  debug;

有关示例配置,请查看:https://github.com/rtCamp/easyengine/blob/master/conf/nginx/singlesite/basic.conf

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9002245

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档