Hello I am using laravel 4 on Nginx with FastCGI, I am pretty new to Nginx and FastCGI.
The situation is when I use the urls as $doc_root/index.php?my_uri it works but when I try pretty URLs it does not work.
this is my nginx configuration
server {
listen 80;
server_name localhost;
rewrite_log on;
index index.php;
root /home/mostafa/public_html;
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
if (!-d $request_filename) {
rewrite ^/(.+)/$ /$1 permanent;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
#pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~* \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /home/mostafa/public_html$fastcgi_script_name;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
location ~* \.(?:ico|css|js|jpe?g|JPG|png|svg|woff)$ {
expires 365d;
}
}
and this is my FastCGI file
;prefix = /path/to/pools/$pool
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
; will be used.
user = www-data
group = www-data
; The address on which to accept FastCGI requests.
; Valid syntaxes are:
; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific address on
; a specific port;
; 'port' - to listen on a TCP socket to all addresses on a
; specific port;
; '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = /var/run/php5-fpm.sock
The case is when I try a url like this
http://localhost/laravel-master/public/index.php?current
it works and when I try it with out the index.php it does not work, and gives a file not found and in error log it says
FastCGI sent in stderr: "Primary script unknown" while reading
although according to this tutorial it should work
http://daylerees.com/nginx-configuration-for-daylerees-dot-com
Ok after searching for a few while and so many try outs, I found that the error was in my nginx config document root, it must be set to laravel-master/public/
The error I was getting was because the rewritten URLs were forwarded to $document_root/index.php
which is localhost/index.php
which of course does not exist, so changing the document root to my laravel master did the trick and the URLs where rewritten to localhost/laravel-master/public/index.php