您好我在Nginx上使用laravel 4和FastCGI,我对Nginx和FastCGI都很陌生。
情况是当我使用url作为$ doc_root / index.php?my_uri它可以工作但是当我尝试漂亮的URL它不起作用。
这是我的nginx配置
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;
}
}
这是我的FastCGI文件
;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
案例是我尝试这样的网址时
http://localhost/laravel-master/public/index.php?current
它有效,当我尝试使用index.php它不起作用,并提供一个未找到的文件,并在错误日志中显示
在stderr发送的FastCGI:"主要脚本未知"在阅读时
虽然根据本教程,它应该可以工作
http://daylerees.com/nginx-configuration-for-daylerees-dot-com
答案 0 :(得分:0)
在搜索了几次尝试之后好了,我发现错误发生在我的nginx配置文件根目录中,它必须设置为laravel-master/public/
我得到的错误是因为重写的网址被转发到$document_root/index.php
localhost/index.php
当然不存在,所以将文档根目录更改为我的laravel master就可以了解诀窍和URL在哪里重写为localhost/laravel-master/public/index.php