Laravel 4 的 nginx 配置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21091405/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
nginx configuration for Laravel 4
提问by pyprism
I am trying to setup my Laravel 4 project using nginx . Here is my nginx server block for laravel :
我正在尝试使用 nginx 设置我的 Laravel 4 项目。这是我用于 laravel 的 nginx 服务器块:
server {
listen 80;
root /home/prism/www/laravel/public;
index index.php index.html index.htm;
server_name example.com;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
But my problem is , Its showing "404 not found" error for all other routes except the default one , that comes with default installation .
但我的问题是,除了默认安装的默认路由之外,所有其他路由都显示“404 not found”错误。
回答by ajtrichards
This is an NGINX Configuration i've used with Laravel 4 and Laravel 4.1 that works.
这是我在 Laravel 4 和 Laravel 4.1 中使用的 NGINX 配置,该配置有效。
server {
listen 80;
server_name sub.domain.com;
set $root_path '/var/www/html/application_name/public';
root $root_path;
index index.php index.html index.htm;
try_files $uri $uri/ @rewrite;
location @rewrite {
rewrite ^/(.*)$ /index.php?_url=/;
}
location ~ \.php {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index /index.php;
include /etc/nginx/fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
root $root_path;
}
location ~ /\.ht {
deny all;
}
}
回答by Rob Gordijn
you could try this for location / { ... }
你可以试试这个位置 / { ... }
location / {
try_files $uri $uri/ /index.php?$query_string;
}
$query_string worked for me.
$query_string 对我来说有效。