Here is the problem :
(I'm new to NGinx, read about it, but didn't find my working solution yet.)
I'm on a Windows system.
My projects file system is located there :
E:/www/
here is a project folder I will try to reach later in this example :
E:/www/projectTest
I have an apache server running fine. I'd like to set up a Nginx server in parallel, this is why i configured my nginx using another port (see config file below).
Nginx files are there :
E:/nginx/
I copied a php there :
E:/nginx/php/
Here is my example 'index.php' I place in my current folders to test my php and nginx config :
<?php
echo "THIS IS A TEST";
?>
Here is my nginx.conf file (I removed commented lines) :
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;
}
}
}
Looks like everything is running fine,
Meaning that if I wan to reach my 'localhost:8111/index.php' or 'localhost:8111/projectTest/index.php', I get the 'index.php' i placed there and the text "THIS IS A TEST" appears on my screen.
BUT :
I noticed that, when I open Firebug to test my page, I always receive this as error message (EVEN IF I GET MY PAGE) :
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
Here is how I start Nginx in command line :
E:\nginx>nginx.exe
E:\nginx\php>php-cgi.exe -b 127.0.0.1:9000 -c e:/nginx/php/php.ini
in php.ini :
doc_root = "E:/www"
extension_dir = "E:/nginx/php/ext"
error_reporting = E_ALL
There must be something wrong in my nginx configuration,
I'm coming from Apache so I'm really confused with this .conf file,
I read many things about it but I'm still not comfortable at all with the "root" or "alias" values, and with the fast-cgi php thing…
Thanks for reading/help/advices
Best Answer
There are several issues in your configuration:
root
on the server level, and then specifyalias
inlocation
blocks. This isn't wrong in itself, but causes confusion easily.If all your project files are under
E:/www
, I would use these remove both thelocation
block withalias
blocks, and would set up onlyroot E:/www
inside theserver
block.root
directive inside your.php
processing block. That won't work.If you don't have any special requirements for your web server, I would use this setup for PHP:
With this setup, nginx will look up your files to be served from
E:/www
directory, and it will pass any PHP files to PHP-FPM for execution.