问题在于:(我是NGinx的新手,请仔细阅读,但没有find我的工作解决scheme。)
我在Windows系统上。
我的项目文件系统位于:
E:/www/
这里是一个项目文件夹,我将尝试在本例中稍后介绍:
E:/www/projectTest
我有一个Apache服务器运行良好。 我想build立一个Nginx服务器并行,这就是为什么我使用另一个端口configuration我的nginx(见下面的configuration文件)。
Nginx的文件在那里:
E:/nginx/
我在那里复制了一个PHP:
E:/nginx/php/
这里是我的例子'index.php'我放在我目前的文件夹来testing我的php和nginxconfiguration:
<?php echo "THIS IS A TEST"; ?>
这里是我的nginx.conf文件(我删除了注释行):
worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 8111; server_name localhost; root E:/nginx/; index index.php index.html index.htm; charset utf-8; location / { alias E:/www/; } location /projectTest/ { alias E:/www/projectTest/; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } location ~ \.php$ { root ../www; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root/conf/$fastcgi_script_name; include fastcgi_params; } } }
看起来像一切运行良好,这意味着如果我想要达到我的'localhost:8111 / index.php'或'localhost:8111 / projectTest / index.php',我得到'index.php'我放在那里和在我的屏幕上出现“THIS IS A TEST”这样的文字。
但是:
我注意到,当我打开Firebug来testing我的页面时,我总是收到这个错误信息(即使我得到我的页面):
NetworkError: 404 Not Found - http://localhost:8111/ //Same error when I call index.php in url : NetworkError: 404 Not Found - http://localhost:8111/index.php //Same error when I call my projectTest folder : NetworkError: 404 Not Found - http://localhost:8111/projectTest/ //Same error when I call my index.php in projectTest url : NetworkError: 404 Not Found - http://localhost:8111/projectTest/index.php
这里是我如何启动Nginx的命令行:
E:\nginx>nginx.exe E:\nginx\php>php-cgi.exe -b 127.0.0.1:9000 -ce:/nginx/php/php.ini
在php.ini中:
doc_root = "E:/www" extension_dir = "E:/nginx/php/ext" error_reporting = E_ALL
在我的nginxconfiguration中一定有什么问题,我是从Apache来的,所以我对这个.conf文件感到困惑,我读了很多东西,但是我仍然不太习惯“root”或者“别名“值,并与fast-cgi的PHP的东西…
感谢您的阅读/帮助/build议
在你的configuration中有几个问题:
root ,然后在location块中指定alias 。 这本身并没有错,但很容易造成混乱。 如果你所有的项目文件都在E:/www ,我将使用这些location块去除alias块,并且只在server块内build立root E:/www 。
.php处理块中指定root指令。 这是行不通的。 如果您对Web服务器没有任何特殊要求,那么我将使用PHP的这个设置:
location ~ \.php$ { try_files $uri =404; include /etc/nginx/fastcgi_params; fastcgi_split_path_info ^(.+\.php)(.*)$; fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; }
使用这个设置,nginx会查找你要从E:/www目录下的文件,并将任何PHP文件传递给PHP-FPM执行。