[英]Laravel4-nginx-fpm file not found on rewrite
您好,我在使用FastCGI的Nginx上使用laravel 4,我對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
的URL時, http://localhost/laravel-master/public/index.php?current
它有效,當我嘗試使用index.php時,它不起作用,並給出了一個文件找到並在錯誤日志中說
在閱讀時在stderr中發送了FastCGI:“主腳本未知”
雖然根據本教程它應該可以工作
http://daylerees.com/nginx-configuration-for-daylerees-dot-com
在搜索了很多次嘗試之后,確定了,我發現錯誤出在我的laravel-master/public/
配置文檔根目錄中,必須將其設置為laravel-master/public/
我收到的錯誤是因為重寫的URL被轉發到$document_root/index.php
,它是localhost/index.php
,這當然不存在,因此將文檔根目錄更改為我的laravel master可以解決問題,並且重寫URL到localhost/laravel-master/public/index.php
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.