我的配置服务器在 nginx 上有问题。
我的配置:
server {
listen 80;
server_name shop.md;
index index.php index.html index.htm;
access_log /var/log/nginx/test.dev.access.log;
error_log /var/log/nginx/test.dev.error.log;
location / {
root /home/vagrant/Workspace/shop/web;
try_files $uri $uri/ app_dev.php /app_dev.php$is_args$args;
}
location ~ .php$ {
root /home/vagrant/Workspace/shop/web;
index index.html index.htm index.php;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param APPLICATION_ENV development;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
}
sendfile off;
}
此配置允许这样的网址:
http://shop.md:8000/1/femei-pantofi
http://shop.md:8000/1/femei-pantofi?min_price=1&max_price=1000
对于此网址:
http://shop.md:8000
我收到错误403 Forbidden
答案 0 :(得分:1)
我使用nginx的@rewriteapp
directive作为我的Symfony2项目。结果配置看起来像这样:
# strip app.php/ prefix if it is present
rewrite ^/app\.php/?(.*)$ /$1 permanent;
location / {
index app.php;
try_files $uri @rewriteapp;
}
location @rewriteapp {
rewrite ^(.*)$ /app.php/$1 last;
}
# pass the PHP scripts to FastCGI server from upstream phpfcgi
location ~ ^/(app|app_dev|adminer)\.php(/|$) {
fastcgi_pass phpfcgi-siyabonga;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
}
这对我来说效果很好,并且从official nginx wiki page about Symfony2获取了一些额外的更改。您还应该查看官方的Symfony2文档。他们有example of a correct nginx configuration。