繁体   English   中英

找不到Symfony2 + Nginx 404

[英]Symfony2 + Nginx 404 not found

我在用nginx配置Symfony2时遇到问题

我这样安装了symfony2

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

一切顺利,当我在配置页面上时没有错误 在此处输入图片说明

但是当我单击“在线配置”或“购买通过”配置时,我无法登录到nginx 404

这是配置文件

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;
}
}

注意:我发现单击“购买通行证”时发现我登陆了类似.... symf / web / app_dev.php /的链接/删除了上一个/允许我到达该页面但出现错误 在此处输入图片说明 单击确定-> 404找不到

我想念什么吗?

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

删除该部分

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

try file之后,您已经在此处重新try file ,应该怎么做

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

并且确保您重新加载了Nginx服务

在不知道服务器配置的情况下很难提出建议,但是这是我的工作配置,它工作得很好(对于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;
    }
}

看起来问题出在nginx上,切换到apache2并立即运行

编辑:如果有人知道nginx发生了什么,conf文件是否错误? 我想知道

暂无
暂无

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

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