我正在使用FOSUserBundle,遇到一个我无法纠正的错误。 (我使用Symfony 3.2.9)
我想它来自我的security.yml文件,但我找不到是什么导致了我的路径错误。
这可能只是一个细节,但我使用的是nginx,我的本地网址是:127.0.0.1:83 / app_dev.php /.
只有我的/登录路线不起作用。
我的网址为/login
,但我将其重定向到/login/
我得到了:No route found for "GET /login/" (from "http://127.0.0.1:83/app_dev.php/")
这是我的security.yml文件:
security:
encoders:
FOS\UserBundle\Model\UserInterface: bcrypt
role_hierarchy: ~
providers:
fos_userbundle:
id: fos_user.user_provider.username
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
pattern: ^/
form_login:
provider: fos_userbundle
csrf_token_generator: security.csrf.token_manager
logout: true
anonymous: true
access_control:
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin/, role: ROLE_ADMIN }
我的config.yml(fosuserbundle配置):
# FOSUser Configuration
fos_user:
db_driver: orm
from_email:
address: my@email.fr
sender_name: Admin
firewall_name: main
user_class: ProjectBundle\Entity\User\User
registration:
form:
type: ProjectBundle\Form\RegistrationType
php bin/console debug:router
:
admin_user_index ANY ANY ANY /admin/user/
admin_user_show ANY ANY ANY /admin/user/{id}/show
admin_user_edit ANY ANY ANY /admin/user/{id}/edit
admin_user_new ANY ANY ANY /admin/user/create
home ANY ANY ANY /
lexik_translation_overview GET ANY ANY /admin/translations/
lexik_translation_grid GET ANY ANY /admin/translations/grid
lexik_translation_new GET|POST ANY ANY /admin/translations/new
lexik_translation_invalidate_cache GET ANY ANY /admin/translations/invalidate-cache
lexik_translation_list GET ANY ANY /admin/translations/api/translations
lexik_translation_profiler GET ANY ANY /admin/translations/api/translations/profiler/{token}
lexik_translation_update PUT ANY ANY /admin/translations/api/translations/{id}
lexik_translation_delete_locale DELETE ANY ANY /admin/translations/api/translations/{id}/{locale}
lexik_translation_delete DELETE ANY ANY /admin/translations/api/translations/{id}
fos_user_security_login GET|POST ANY ANY /login
fos_user_security_check POST ANY ANY /login_check
fos_user_security_logout GET|POST ANY ANY /logout
fos_user_registration_register GET|POST ANY ANY /register/
fos_user_registration_check_email GET ANY ANY /register/check-email
fos_user_registration_confirm GET ANY ANY /register/confirm/{token}
fos_user_registration_confirmed GET ANY ANY /register/confirmed
编辑:更多信息
我的routing.yml:
project:
resource: "@ProjectBundle/Controller/"
type: annotation
prefix: /
fos_user:
resource: "@FOSUserBundle/Resources/config/routing/all.xml"
登录路径的routing.xml:FOSUserBundle Routing File
也许我的问题来自我的Nginx配置(这是我第一次使用它):
server {
listen 83 default_server;
listen [::]:83 default_server;
server_name localhost;
root /var/www/html/MyProject/web;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
location / {
try_files $uri /app.php$is_args$args;
}
location ~ ^/(app|app_dev|app_test|config)\.php(/|$) {
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
有人有想法吗?我真的陷入了我的项目。 提前谢谢。
答案 0 :(得分:0)
No route found for "GET /login/"
表示该路线不存在并且是正确的,如果您查看php bin/console debug:router
,您可以看到该路线为/login
而不是/login/
,请删除最后一个斜线< / p>
答案 1 :(得分:0)
Symfony设置看起来不错。我在当地重复了一遍。适用于apache2和nginx。 我建议玩nginx配置文件。位置部分看起来很可疑。