Search code examples
phpsymfonysubdomain

Symfony 3 : Routing with subdomain don't work on prod


This will make 6 hours that I am on the problem, I have a routing with host requirements, to handle subdomain. It works perfectly in dev but in staging this repeats me the same error no matter what I do:

No route found for "GET /login"" at /var/www/app/var/cache/prod/classes.php

Here is my routing :

app_front_office:
    resource: "@AppFrontOfficeBundle/Resources/config/routing.yml"
    prefix:   /
    host: "%front_office_domain%"

app_back_office:
   resource: "@AppBackOfficeBundle/Resources/config/routing.yml"
   prefix:   /
   host: "%back_office_domain%"

security.yml :

firewalls:
    dev:
        pattern: ^/(_(profiler|wdt)|css|images|js)/
        security: false

    main:
        pattern: ^/
        anonymous:  true
        form_login:
            login_path: app_back_office_security_login
            check_path: app_back_office_security_login
        logout:
            path: app_back_office_security_logout
            target: app_back_office_dashboard_index
        remember_me:
            secret: '%secret%'
            lifetime: 2630000
            path: app_back_office_dashboard_index
            always_remember_me: true
            domain: '%cookie_domain%'
            user_provider: main_provider

access_control:
    - { host: '%back_office_domain%',path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { host: '%back_office_domain%',path: ^/, role: ROLE_ADMIN }

parameters.yml :

cookie_domain: .domain.com
front_office_domain: staging.domain.com
back_office_domain: bo-staging.domain.com

debug:router :

app_front_office_homepage                     ANY        ANY staging.domain.com      /                                  
fos_js_routing_js                                ANY        ANY      ANY                     /js/routing.{_format}              
app_back_office_dashboard_index               GET        ANY      bo-staging.domain.com   /                                  
app_back_office_security_login                GET|POST   ANY      bo-staging.domain.com   /login                             
app_back_office_security_logout               ANY        ANY      bo-staging.domain.com   /logout                            
app_back_office_subscription_plan_list_ajax   GET        ANY      bo-staging.domain.com   /subscriptions/list                
app_back_office_user_index                    GET        ANY      bo-staging.domain.com   /users                             
app_back_office_user_profile                  GET        ANY      bo-staging.domain.com   /users/profile/{userId}            
app_back_office_user_update_field_ajax        POST       ANY      bo-staging.domain.com   /users/updateField                 
app_back_office_user_delete_ajax              DELETE     ANY      bo-staging.domain.com   /users/delete/{userId}             
app_back_office_user_recover_ajax             POST       ANY      bo-staging.domain.com   /users/recover/{userId}            
app_back_office_user_list_ajax                GET        ANY      bo-staging.domain.com   /users/list

nginx conf :

    server {
        listen       443 default_server ssl;

        server_name staging.domain.com api-staging.domain.com dashboard-staging.domain.com bo-staging.domain.com;
        root /var/www/wapp/web;


        ssl on;
            ssl_certificate      /etc/nginx/ssl/ssl-bundle.crt;
            ssl_certificate_key  /etc/nginx/ssl/domain_com.key;
        #   ssl_session_timeout  5m;
            ssl_protocols TLSv1 TLSv1.1 TLSv1.2;


        location / {
            try_files $uri /app.php$is_args$args;
        }
        # PROD
        location ~ ^/app\.php(/|$) {
            fastcgi_pass unix:/run/php/php7.0-fpm.sock;
            fastcgi_split_path_info ^(.+\.php)(/.*)$;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
            fastcgi_param DOCUMENT_ROOT $realpath_root;
            internal;
        }

        location ~ \.php$ {
            return 404;
        }

        error_log /var/log/nginx/app_error.log;
        access_log /var/log/nginx/app_access.log;
    }


    # HTTP server
    server {
        listen      80;
        server_name  staging.domain.com api-staging.domain.com dashboard-staging.domain.com bo-staging.domain.com;
        root /var/www/app/web;

        location / {
            return 301 https://$server_name$request_uri;
        }
    }

Thanks for your help, I will go crazy if I can not fix the problem :p


Solution

  • Thank everyone for your help, I found the anwser. The load balancer health checker was configured to check the "/login" path and I wasn't aware of this configuration so that explain the error.