简体   繁体   English

找不到Symfony2 + Nginx 404

[英]Symfony2 + Nginx 404 not found

I'm having trouble configuring Symfony2 with nginx 我在用nginx配置Symfony2时遇到问题

I installed symfony2 like this 我这样安装了symfony2

php composer.phar create-project symfony/framework-standard-edition /var/www/symf php composer.phar创建项目symfony / framework-standard-edition / var / www / symf

everything went smoothly, when i'm on the config page no erros 一切顺利,当我在配置页面上时没有错误 在此处输入图片说明

but when i click Configure online or Buypass config i'm landing on nginx 404 NOT FOUND 但是当我单击“在线配置”或“购买通过”配置时,我无法登录到nginx 404

here is the config file 这是配置文件

upstream phpfcgi {
server 127.0.0.1:9000;
}

server {
listen 80;

server_name localhost;
root /var/www/symf/web;

error_log /var/log/nginx/symfony2.error.log;
access_log /var/log/nginx/symfony2.access.log;

# 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|config)\.php(/|$) {
    fastcgi_pass phpfcgi;
    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    include fastcgi_params;
    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param  HTTPS off;
}
}

Note : i noticed when clicking buypass i'm landing on a link like ....symf/web/app_dev.php/ removing last / allow me to reach the page but got and error 注意:我发现单击“购买通行证”时发现我登陆了类似.... symf / web / app_dev.php /的链接/删除了上一个/允许我到达该页面但出现错误 在此处输入图片说明 clicking ok -> 404 no found 单击确定-> 404找不到

i'm i missing something ? 我想念什么吗?

parameters.yml parameters.yml

    database_driver: pdo_mysql
database_host: 127.0.0.1
database_port: null
database_name: symfony
database_user: root
database_password: *****
mailer_transport: smtp
mailer_host: 127.0.0.1
mailer_user: null
mailer_password: null
locale: fr
secret: ******
debug_toolbar: true
debug_redirects: false
use_assetic_controller: true

Remove that part 删除该部分

# strip app.php/ prefix if it is present
rewrite ^/app\.php/?(.*)$ /$1 permanent;

You are already rewritting here after the try file which is how it should be done try file之后,您已经在此处重新try file ,应该怎么做

location @rewriteapp {
    rewrite ^(.*)$ /app.php/$1 last;
}

And ofc make sure you reload your nginx service 并且确保您重新加载了Nginx服务

It's difficult to suggest somthing without knowing about your server configuration, but here is my working config, which works very fine (for nginx-php-fpm), may be it helps you: 在不知道服务器配置的情况下很难提出建议,但是这是我的工作配置,它工作得很好(对于nginx-php-fpm),也许可以帮助您:

server {
    listen   80;
    server_name my_site.dev *.my_site.dev;
    root /var/www/my_site.dev/public_html/web;

    error_log /var/log/nginx/my_site_error.log;
    access_log /var/log/nginx/my_site_access.log;

    rewrite ^/app\.php/?(.*)$ /$1 permanent;

    try_files $uri @rewriteapp;

    location @rewriteapp {
        rewrite ^(.*)$ /app.php/$1 last;
    }

    # Deny all . files
    location ~ /\. {
        deny all;
    }

    location ~ ^/(app|app_dev)\.php(/|$) {
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_index app.php;
        send_timeout 1800;
        fastcgi_read_timeout 1800;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
    }

    # Statics
    location /(bundles|media) {
        access_log off;
        expires 30d;

        # Font files
        #if ($filename ~* ^.*?\.(eot)|(ttf)|(woff)$){
        #       add_header Access-Control-Allow-Origin *;
        #}

        try_files $uri @rewriteapp;
    }
}

Looks like the issue was with nginx, switching to apache2 and worked instantly 看起来问题出在nginx上,切换到apache2并立即运行

EDIT : if anyone has a clue of what is going on with nginx, is the conf file wrong ? 编辑:如果有人知道nginx发生了什么,conf文件是否错误? i would like to know 我想知道

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM