不懂就问系列: PHP 网站使用 nginx 遇到的一些问题
准备使用 php 做个网站,域名是 dev.hellotools.org,根目录下有四个文件,分别是,
index.php,就是主页了about.php,关于页面404.php,也就是 404 页面了/a/b/page.php,a 和 b 是目录,意思就是根目录下有个二级目录,里边有个page.php
现在我想实现以下功能,
- 访问
dev.hellotools.org时,浏览器上地址栏显示dev.hellotools.org,且浏览器显示index.php的内容; - 访问
dev.hellotools.org/about时,浏览器上地址栏显示dev.hellotools.org/about,且浏览器显示about.php的内容; - 访问
dev.hellotools.org/nono时,浏览器上地址栏显示dev.hellotools.org/nono,且浏览器显示404.php的内容; - 访问
dev.hellotools.org/a/b/page时,浏览器上地址栏显示dev.hellotools.org/a/b/page,且浏览器显示/a/b/page.php的内容
于是我的 nginx 配置如下,
server { listen 80; server_name dev.hellotools.org; index index.html index.htm index.php default.html default.htm default.php; root /home/wwwroot/dev.hellotools.org; charset utf-8; error_page 404 /404.php; ## enable php path info location ~ [^/].php(/|$) { fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_index index.php; include fastcgi.conf; include pathinfo.conf; } location / { try_files $uri $uri.php /index.php; } }
搞不清楚我的配置哪里有问题,在访问 about 页面的时候,竟然文件直接下载了,404 也出不来,不知道哪里出问题了。
每个页面的内容都写清楚了,就几个简单的汉字和字母。比如你打开的是 index.php,那么页面内容就有:index.php。其它都是类似的。
折腾一晚上了,实在找不出了,望有了解的大兄弟指点一下。